Angular how to change environment variable values after build
Posted on March 24, 2022
Sample environment variables for development & production environment.ts
export const environment = {
env: 'Dev'
};
environment.prod.ts
export const environment = {
env: 'Prod'
};
In the above code using the window object like below:
environment.ts
export const environment = {
env: window['env'] || 'Dev'
};
environment.prod.ts
export const environment = {
env: window['env'] || 'Prod'
};
Create a .js
file in the root directory and add it to index.html
file as a script
<script src="./config.js"></script>
In the config.js
file, you can update the environment values without rebuilding your application like below:
window['env'] = 'Uat';
to join this conversation on Samprix.Already have an account? Sign in to comment