如何为在app.module中导入的模块提供运行时配置数据?

时间:2018-10-04 15:42:35

标签: angular

我正在使用在AppModule中导入的MsAdalAngular6Module,我需要能够在运行时从外部json文件提供配置值:

@NgModule({
declarations: [AppComponent, HeaderComponent, SidebarComponent],
imports: [
CommonModule,
BrowserModule,
HttpClientModule,
MsAdalAngular6Module.forRoot( {tenant: config.tenantId,
  clientId: config.clientId,
  redirectUri: window.location.origin,
  endpoints: {
    string: ''
  },
  navigateToLoginRequestUrl: false,
  cacheLocation: 'localStorage'}),
AppRoutingModule

我正在Docker中使用多阶段构建和nginx运行它。理想情况下,我希望此模块配置的默认值来自环境文件,但应在运行时由外部json文件中的值取代。

我已经看到了几种解决方法,包括Angular 2: External configuration befor bootstrap - passing the value to AppModule,但是在导入和配置MsAdalAngular6模块

之前,我似乎永远无法向app.module提供值。

0 个答案:

没有答案