Where to define common environment variables in angular 4

Viewed 1624

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.

1 Answers

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.

Related