我使用的是带有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

我该怎么解决呢?


当前回答

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

其他回答

我在使用动态组件的ag网格中遇到了同样的问题。我发现你需要在ag-grid模块中添加动态组件。withcomponents []

进口:[ StratoMaterialModule, BrowserModule, AppRoutingModule, HttpClientModule, BrowserAnimationsModule, NgbModule.forRoot (), FormsModule, ReactiveFormsModule, AppRoutingModule, AgGridModule.withComponents (ProjectUpdateButtonComponent) ],

我也有同样的问题。在这种情况下进口[…]]是至关重要的,因为如果你不导入NgbModalModule,它将无法工作。

错误描述说组件应该添加到entryComponents数组中,这是显而易见的,但请确保您已经在第一个位置添加了这个:

imports: [
    ...
    NgbModalModule,
    ...
  ],

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

我在Angular7中创建动态组件时也遇到了同样的问题。有两个组件(TreatListComponent, MyTreatComponent)需要动态加载。我只是在我的app.module.ts文件中添加了entryComponents数组。

    entryComponents: [
    TreatListComponent,
    MyTreatComponent
  ],

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