Reputation: 15712
With Angular2 you can use src/environments/environment.ts
and *.prod.ts
to configure either production or development environments. Now we have a huge staging requirements and we will need e.g. 5-10 API Urls. How to set and read environment variables other than --prod
or --dev
with angular-cli, e.g. URL="http://server12a"
?
Upvotes: 2
Views: 459
Reputation: 1599
You can have all different kind of environments. Define each of those in your angular-cli.json file:
"environments": {
"local": "environments/environment.ts",
"test": "environments/environment.test.ts",
"staging ": "environments/environment.staging.ts",
"prod": "environments/environment.prod.ts"
}
Within these files you can have something along the lines of:
export const environment = {
URL="http://server12a"
};
When you build you have to specify the right environment like:
ng build --env=staging
Upvotes: 3