Change part of the link depends of environment in typescript

6/29/2021

I would like to add the link to some field and part of that link should differ depends on the used environment. Lets say that I have dev and prod environment.

I think that I should somehow put these variables to application.yaml (maybe kubernetes here would be helpful?) but I don't know how to access these variables in typescript file. I'm using spring in my project with the application.yaml file. Could you give me some tips how I should achieve that or sent a link for helpful articles?

-- Koin Arab
angular
configmap
kubernetes
spring
typescript

1 Answer

6/29/2021

You can use some files, usually called environment.[xyz].ts, to achieve some configuration depending on the type of build configured in your angular.json file.

For more informations: https://angular.io/guide/build

=== EDIT ===

If you need it to be a runtime configuration, you can create a JSON file into src/assets/, retrieve it and parse it with a service by making a simple http call, like: this.http.get('/assets/xyz.json') and storing the configuration inside the service.

To be sure that when you will use this service (via injection) the configuration will be already loaded, you can set its load configuration fuction to be executed on app startup with the APP_INITIALIZER DI token.

This tutorial explains in details what I'm suggesting.

-- Thomas Iommi
Source: StackOverflow