这是一个angular模块的问题。
我有几个导出为npm-package的模块,我的应用程序需要这两个模块。让我们称它们为Inner和Outer模块。
在应用程序中,我配置了Inner,并使用它的InnerModuleService。
在OuterModule中,我也有InnerModule依赖项,并且需要与应用程序中相同的InnerModuleService。
但是我不知道如何从我的应用程序传递InnerModule的配置。有人能帮我吗?
以下是更具说明性的代码片段
#NPM-Package
let innerModuleConfig;
@NgModule({
imports: [
CommonModule,
InnerModule.forChild({
config: innerModuleConfig
})
],
exports: [InnerModule]
})
export class OuterModule {
static forRoot(config: any): ModuleWithProviders {
innerModuleConfig = config.innerModuleConfig;
return {
ngModule: OuterModule,
providers: [InnerModuleService]
};
}
}
#APP
let appInnerModuleConfig = {};
@NgModule({
imports: [
OuterModule.forRoot({
innerModuleConfig: appInnerModuleConfig
})
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}发布于 2018-04-01 22:36:19
您可以使用带有模块文件路径的loadChildren属性来执行此操作,然后使用hash #引用模块本身。
https://stackoverflow.com/questions/49598556
复制相似问题