I am new to angular 4. I have a set of properties that is common for all environments such as dev, staging, prod etc. Where can I place those properties in angular 4?.
I have read about environments but there I have to copy the same properties to all environment files ie. environment.ts, environment.prod.ts etc.
-
1Anywhere you want. You export them from a TypeScript file, and import them where you need them.JB Nizet– JB Nizet2017-11-25 10:52:00 +00:00Commented Nov 25, 2017 at 10:52
-
@JBNizet Thanks. Is not possible with environment.ts?Cracker– Cracker2017-11-25 10:57:01 +00:00Commented Nov 25, 2017 at 10:57
-
environment.ts is designed for things that depends on the environment. You just have some constants, that don't depend on the environment. So define them anywhere you want, except in environment.ts.JB Nizet– JB Nizet2017-11-25 10:59:51 +00:00Commented Nov 25, 2017 at 10:59
-
@JBNizet Thanks a lotCracker– Cracker2017-11-25 11:01:02 +00:00Commented Nov 25, 2017 at 11:01
Add a comment
|
1 Answer
Create a new environment.common.ts file and then import it inside each of your environments files.
environment.common.ts
export const commonEnvironment = {
property1: "value"
};
environment.ts and environment.prod.ts etc...
import { commonEnvironment } from './environment.common';
export const environment = {
production: false,
common: commonEnvironment
};
You have to use the common property to use your sub properties.