Cracker
Cracker

Reputation: 73

Where to define common environment variables in angular 4

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.

Upvotes: 3

Views: 2001

Answers (1)

Nicolas Law-Dune
Nicolas Law-Dune

Reputation: 1703

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.

Upvotes: 11

Related Questions