Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular6 using system environment variables in environment.ts

In my Angular4 application i ejected the webpack config and used dotenv module to read from a .env file and use those config variables in the application. Since i updated to Angular6 the "ng eject" is depricated and i am using angular-cli. I am looking for a workaroud for this problem (either using a config file or system environment variables).

If i can make a reference in Spring Framework in the application.properties file

spring.datasource.username = ${MYSQL_DB_USERNAME}

MYSQL_DB_USERNAME is environment variable. I would like to use this behavior in environment.ts

like image 479
Ivan Kirchev Avatar asked Dec 02 '25 13:12

Ivan Kirchev


1 Answers

I dont think you are able to do that unless maybe you are using SSR? Webpack for angular 6 at the moment is disabled, they said they would re-add with some customization but majority will be done in angular.json. so for now no ng eject.

I think the best approach might be to make a restApi call to your backend on bootstrap to load and retrieve any variables you may require.

Ng Eject: https://github.com/angular/angular-cli/issues/10618

like image 167
Taranjit Kang Avatar answered Dec 04 '25 03:12

Taranjit Kang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!