Angular 5在app.module.ts中使用运行时环境变量 [英] Angular 5 Use runtime environment variables in app.module.ts

查看:237
本文介绍了Angular 5在app.module.ts中使用运行时环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于身份验证的第三方模块-OktaAuthModule.

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

要将其导入到我的根模块(app.module.ts)中,首先需要像这样配置它-

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.

使用内置的"ng build --env"可以正常工作,但需要多次构建.在处理完此导入"数组之后,APP_INITIALIZER挂钩似乎开始运行.

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.

我希望进行一次API调用,该API调用可以在每次部署应用程序时提取此信息.我不知道在哪里可以在app.module.ts文件中添加此代码?

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.

推荐答案

在为不同环境制定Bamboo部署计划时,我遇到了类似的问题.每个环境都必须有专门的版本.我不太喜欢它,所以我最终完成了main.js的自动编辑.环境变量嵌入其中,因此您可以像我一样对每个enc进行修改.

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.

这篇关于Angular 5在app.module.ts中使用运行时环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆