首页 > 解决方案 > 角度 ngmodule 的加载配置

问题描述

我正在platformBrowserDynamic像这样加载配置数据:

 platformBrowserDynamic([{ provide: MyConfig, useValue: new MyConfig(data.config) }]) 

MyConfig是一个类:

export class MyConfig {
  setting1: string;
  setting2: string;
  other: {}

  constructor(data: any) {
   this.setting1 = data.setting1;
   this.setting2 = data.setting2;
   this.other = data.other;
  }
}

我的MyCustomModule

    export function someFactoryTest() {
     debugger; //<--got debugger steps here
     return 'something';
    }

   export function initializeConfig(config: MyConfig) {
     debugger; //<--debugger does not steps here and no errors in console.
     return config.other;
    }

    @NgModule({
      imports: [
        MyOtherModule.forRoot(initializeConfig, someFactoryTest) //<-- I want to be able to pass my params here
      ],
    })
    export class MyCustomModule {}

我无法获取值表单MyConfig,尝试调试,但有趣的是调试器根本没有initializeConfig介入

你有什么想法可以解决这个问题吗?

标签: angularconfigurationangular-module

解决方案


推荐阅读