Andriy Zhuk
Andriy Zhuk

Reputation: 143

How to reference other environment properties inside of environment.ts file in Angular project?

I'm trying to modify the 'environment.ts' file in Angular project and add some additional properties to it. What I have is:

export const environment = {
  production: false,
  apiUrl: 'http://example.com',
  authApiUrl: 'http://example.com/auth'
};

The question is if it's possible to somehow unify it and reference other properties so that it looked something like:

export const environment = {
  production: false,
  apiUrl: 'http://example.com',
  authApiUrl: apiUrl + '/auth'
};

Upvotes: 3

Views: 1057

Answers (1)

R. Richards
R. Richards

Reputation: 25141

Think about using a constant for this type of thing. Like below.

const apiBase = 'http://example.com';

export const environment = {
  production: false,
  apiUrl: apiBase,
  authApiUrl: apiBase + '/auth'
};

Should give you the results you expect. Works for me in my CLI applications to get more DRY.

Upvotes: 4

Related Questions