I have two environments, one for staging and another for production. They both have different URLs and I want to build my project using Angular CLI. Right now I have to comment one URL and run another. But I want to control these things directly from the environment file.
I used this way (from Different proxy config based on environment in Angular 2 CLI):
// environment.ts
export const environment = {
production: false,
api: 'http://localhost:3000'
};
// environment.prod.ts
export const environment = {
production: true,
api: 'http://api.exampledomain.com'
}
Then in your ts source files pull the domain from the environment file:
// some service
import { Injectable } from '@angular/core';
import { environment } from '../../../environment.ts';
import { Http } from '@angular/http';
@Injectable()
export class SomeService {
constructor(private http: Http);
getData(){
return this.http.get(environment.api + '/rest-of-api');
}
}
But in this if I want to build from production how do I change environment variable value? Because here I import from environment.ts
, not environment.prod.ts
.