Ivan Kirchev
Ivan Kirchev

Reputation: 142

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

Upvotes: 4

Views: 2755

Answers (1)

Taranjit Kang
Taranjit Kang

Reputation: 2580

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

Upvotes: 1

Related Questions