Angular 5 Use runtime environment variables in app.module.ts

Deadly 提交于 2020-01-25 08:36:07

问题


I have a 3rd party module that I am using for authentication- OktaAuthModule.

For it to be imported in my root module (app.module.ts), it needs to first be configured like this-

const config = {
   url: https://myurl.com/
}

@NgModule({
   declarations: [ ... ],
   imports: [
      OktaAuthModule.initAuth(config),
   ],
   ...
});

I need to produce a single build that can be deployed to multiple runtimes, each having a different config for this module.

Using the built-in "ng build --env " works fine, but requires multiple builds. The APP_INITIALIZER hooks seem to run after this "imports" array has been processed.

I was hoping to make an API call that could pull this information each time the app is deployed. I don't have any idea where I can add this code in the app.module.ts file?

Thanks in advance for any advice / suggestions.


回答1:


I came across similar issue when co figuring Bamboo deployment plans for different environments. Every env had to had dedicated build. I didnt like that much so I have ended up in automated editing of main.js. Environment variables are embedded there so you could modify that per enc just like I did.



来源:https://stackoverflow.com/questions/52821346/angular-5-use-runtime-environment-variables-in-app-module-ts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!