Setting up global constants on Angular 2 enviroment

Do you use different API calls on dev, test and production in your Angular 2 application?

If so, you can use CLI ‘./environments/’.  At build time, environments/environment will be replaced by environments/ or environments/, depending on the current CLI environment. You can also add as many environments here as you like. Just remember to define them at ‘./angular-cli.json’.

To reference in your code just use:

import { environment } from ‘../environments/environment’;

And then simply declare and use:

environment: any = environment;

environment.APIURL; // URL to web API



Visual Studio Code extensions for Angular 2 development

Here are two extensions that I have found great for developing on Angular 2.


Automatically finds, parses and provides code actions for all available imports. Only currently works with files in your folder and TypeScript.

ext install autoimport


Angular 2 TypeScript Snippets for VS Code

This extension for Visual Studio Code adds snippets for Angular 2 for TypeScript and HTML.