我想从组件加载模态.在Angular Material文档中写入以在entryComponents中添加模态组件:
这个 :
@NgModule({
imports: [
CommonModule,
AidesRoutingModule
],
declarations: [TypesAidesComponent, TypesAidesAjouterComponent],
entryComponents : [TypesAidesAjouterComponent]
})
export class AidesModule {
}
Run Code Online (Sandbox Code Playgroud)
在TypesAidesComponent中,我想要使用TypesAidesAjouterComponent打开对话框:
let dialog = this.dialog.open(TypesAidesAjouterComponent);
dialog.afterClosed().subscribe(res => {
if(res){
this.collection.addItem(res);
}
});
Run Code Online (Sandbox Code Playgroud)
我在一个组件延迟加载:
{
path: 'types-aides',
loadChildren: 'app/modules/aides/aides.module#AidesModule'
},
Run Code Online (Sandbox Code Playgroud)
但我有这个错误:
错误:找不到TypesAidesAjouterComponent的组件工厂.你有没有把它添加到@ NgModule.entryComponents?
我找到了一个解决方案,它是移动删除LazyLoading,但我的应用程序很大,不可能.
你有什么建议吗 ?
目前,这是Angular的常见投诉。在某些情况下,由于依赖项注入的工作原理,不可能从延迟加载的模块中提取小组件。组件必须通过各自的模块带入应用程序,这意味着如果尚未加载该模块,则不能使用其声明的任何组件。
我不得不接受这样一个事实,那就是,在一个结构良好的应用程序中确实很少有这种需求的出现,而与之抗争应表明我需要重新评估该应用程序的结构。
解决此问题的最佳方法是提取组件并为其创建一个单独的模块,或将其添加到导入到您要在其中渲染该模块的共享模块中。
| 归档时间: |
|
| 查看次数: |
5134 次 |
| 最近记录: |