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/environment.dev.ts or environments/environment.prod.ts, 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.


AutoImport

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

https://marketplace.visualstudio.com/items?itemName=steoates.autoimport

ext install autoimport

2yrf1xesbv

Angular 2 TypeScript Snippets for VS Code

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

https://github.com/johnpapa/vscode-angular2-snippets

use-extension