0

I am working on a development environment in angular and need to add URLs into parts but unfortunately, I can't append the value which is declared inside the environment file.

export const environment = {
    production: false,
    apiRootUrl:  'https://abcd.in/api',
    apiPublicUrl: 'public',
    apiCurrentVersion: 'v1',
    CONST_SLASH: '/',
    apiSsoUrl: 'sso',
    apiBaseUrl: environment.apiRootUrl + environment.CONST_SLASH + environment.apiPublicUrl +                                   
                environment.CONST_SLASH + environment.apiCurrentVersion + environment.CONST_SLASH + 
                environment.apiSsoUrl 
};

But in the apiBaseUrl it's showing an error:

Block-scoped variable 'environment' used before its declaration.
Edric
  • 24,639
  • 13
  • 81
  • 91

1 Answers1

2

You can't set a property to another property in the same object. You can read more here: I need to set a json object property in a object, then reference that property from another object in the same object

A solution would be to create a model or a service, where you create the baseUrl by accessing the environment properties.

Yusuf Ipek
  • 166
  • 1
  • 11
  • Yes I already create a service to append these properties but, can't we concate these properties inside the "envirnment.ts" file ? – Devendra Jadhav Sep 18 '20 at 07:21
  • 1
    No, that is not possible, please have a look at the solution in the link I postet. As noted there "the object has to be initialized before its values can be referred to". – Yusuf Ipek Sep 18 '20 at 08:41
  • so what if I make environmental object as a class in "envirnment.ts" file – Devendra Jadhav Sep 19 '20 at 04:05