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