Assuming that you're using the Angular CLI to scaffold your project (I hope that you are), you should already have access to different environment settings. These files allow you to easily provide values to your application that can vary depending on where it's running.
environment.ts
provides the interface for your environment values and then environment.qa.ts
, environment.prod.ts
, etc (you can create as many environments as you want) allow you to specify different values that correspond to that environment.
Assuming that you have something like this in your environment file:
export const environment = {
myEndpoint: 'localhost:3000'
}
You can run or build the app using the --env flag to get the appropriate values:
ng build --env=qa
Accessing the values defined in your env config are easy. In your service or component just add an import for environment:
import { environment } from '../../environments/environment';
And then use the value:
this.http.get(environment.myEndpoint)