3

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.

4
  • 1
    Anywhere you want. You export them from a TypeScript file, and import them where you need them. Commented Nov 25, 2017 at 10:52
  • @JBNizet Thanks. Is not possible with environment.ts? Commented 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. Commented Nov 25, 2017 at 10:59
  • @JBNizet Thanks a lot Commented Nov 25, 2017 at 11:01

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.