Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to define common environment variables in angular 4

Tags:

angular

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.

like image 664
Cracker Avatar asked Feb 02 '26 03:02

Cracker


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.

like image 99
Nicolas Law-Dune Avatar answered Feb 03 '26 17:02

Nicolas Law-Dune