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

我该怎么解决呢?


当前回答

在我的例子中,我忘记将MatDialogModule添加到子模块的导入中。

其他回答

我对引导模态也有同样的问题

从 '@ng-bootstrap/ng-bootstrap' 导入 { NgbModal };

如果是这种情况,只需像其他响应建议的那样,将组件添加到模块声明和entryComponents中,但也要将此添加到模块中

import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

imports: [
   NgbModule.forRoot(),
   ...
]

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

entryComponents:[ConfirmComponent],

以及声明:

declarations: [
    AppComponent,
    ConfirmComponent
]

我导入材料设计对话框模块,所以我创建了aboutcomponent的对话框,从openDialog方法调用这个组件,然后我得到了这个错误,我只是把这个

declarations: [
    AppComponent,
    ExampleDialogComponent
  ],

  entryComponents: [
    ExampleDialogComponent
  ],

你应该像这样在模块中导入NgbModule:

@NgModule ({ 声明:[ AboutModalComponent ], 进口:[ CommonModule, SharedModule, RouterModule, FormsModule, ReactiveFormsModule, NgxLoadingModule, NgbDatepickerModule, NgbModule ], entryComponents (AboutModalComponent): }) 导出类HomeModule {}

在我的情况下,我解决了这个问题: 1)将NgxMaterialTimepickerModule放在app模块导入中:[] 2)在testmodule中放置NgxMaterialTimepickerModule。Ts导入:[] 3)将testcomponent放在声明中:[]和entryComponents:[]

(我使用的是angular 8+版本)