我使用的是带有webpack的Angular 4模板 当我尝试使用一个组件(ConfirmComponent)时,我有这个错误:

没有为ConfirmComponent找到组件工厂。你加进去了吗 @NgModule.entryComponents吗?

该组件在app.module.server.ts中声明

@NgModule({
  bootstrap: [ AppComponent ],
  imports: [
    // ...
  ],
  entryComponents: [
    ConfirmComponent,
  ],
})
export class AppModule { }

还有app。module。browser。ts和app。module。shared。ts

我该怎么解决呢?


当前回答

在本节中,你必须在app.module.ts文件的以下部分中输入作为子组件使用的组件:[CityModalComponent](模态组件):

 entryComponents: [
CityModalComponent
],

其他回答

如果在entryComponents中提供组件对话框类后仍然有错误,请尝试重新启动ng serve -这对我来说是有效的。

我的错误是在.html中调用NgbModal open方法时参数不正确

在本节中,你必须在app.module.ts文件的以下部分中输入作为子组件使用的组件:[CityModalComponent](模态组件):

 entryComponents: [
CityModalComponent
],

将该组件添加到应用模块的@NgModule的entryComponents中:

entryComponents:[ConfirmComponent],

以及声明:

declarations: [
    AppComponent,
    ConfirmComponent
]

在导入中添加'NgbModalModule',并在entryComponents App.module.ts中添加组件名称,如下所示