简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM