【发布时间】:2018-07-14 02:03:58
【问题描述】:
我有一个需要公开提供程序的延迟加载模块,因此我使用forRoot 约定并返回以下代码:
@NgModule({
imports: [RouterModule.forChild([
{path: "", component: LazyComponent},
])],
declarations: [LazyComponent],
})
export class LazyModule {
static forRoot() {
return {
ngModule: LazyModule,
providers: [provider]
};
}
}
问题是当我在我的应用程序模块中调用 forRoot 时,延迟加载不再起作用。 (我在控制台中没有看到单独的块)
@NgModule({
declarations: [
AppComponent,
HelloComponent
],
imports: [
BrowserModule,
AppRoutingModule,
LazyModule.forRoot() <======== this stops the lazy load module
],
bootstrap: [AppComponent]
})
export class AppModule {
}
据我所知,它应该只使提供者单例,为什么它不起作用?
【问题讨论】:
-
如果你在 Eager 模块中导入 LazyLoad 模块,那么 webpack 不会为它创建块
-
所以你的意思是我不能同时延迟加载我的模块和使用 forRoot?
-
您可以创建仅包含提供程序的单独模块并导入它
标签: javascript angular