Reputation: 6548
In my Angular project, I have multiple different environment configs to support different countries for which I have created one environment file per config like
and so on
But in all of these files, I have 60% of the variables common i.e value of 60% of the variables is the same in all the files.
Rest 30% of the variable's value changes only country-specific i.e. they a variable in India is the same for local, stag and prod, it only changes for Brazil, Australia, and other countries.
Now last 10% of the variable's value changes on each file.
I am looking for a solution where I can have something like commonEnv.ts
file where I can keep all my common environments variables.
Then commonIndia.ts where I can keep all country-specific common variables, like here India specific variables.
And at last individual files for each config which is already seen in Angular.
Is it possible to do so in Angular? Please tell me how.
If not, how can I solve my problem?
Also if we can merge commonEnv.ts, common-contry.ts and config.ts file into single env.ts file on each Angular serve/build would be great.
Upvotes: 1
Views: 491
Reputation: 24472
as a simple solution ,you can create a CommonEnv
object and use it as base configuration for other enverment objects
common-env.ts
export const CommonEnv = {
apiUrl : '127.0.0.1/api',
production : true
}
import the CommonEnv to other environments object like this
environment.ts
export const environment = {
...CommonEnv,
production : false // 👈 change a proprty value come from CommnEnv
};
environment.prod.ts
export const environment = {
...CommonEnv,
apiUrl : '216.58.206.174/api' // 👈 reset the apiUrl
};
Upvotes: 1