我正在尝试使用Nebular
组件在Angular6上创建Web对话框。有两种方法可以实现这一点,第一种是传递<ng-template>
引用,例如:
openAddDialog = (dialogTemplate: TemplateRef<any>) => {
this.dialogServiceRef = this.dialogService.open(dialogTemplate);
}
它现在运行良好。但我需要像这样将组件作为参数传递:
dialogService.open(MyComponent);
我在我的应用程序中有这样的结构:
|_ pages
| |_ pages.module.ts
| |_ patient
| |_ patient.module.ts
| |_ patient.component.ts
| |_ patient.component.html
|
|_ shared
|_ shared.module.ts
|_ components
| |_ search-bar.component.ts
| |_ search-bar.component.html
|
|_ modal-form
|_ modal-form.component.ts
|_ modal-from.component.html
我已将
ModalFormComponent
添加到共享模块的 declarations
、exports
和 entryComponents
中。同时,我在 SearchBar 组件中导入,并在点击 searchBar 中的按钮时运行此函数:openAddDialog = () => {
this.dialogServiceRef = this.dialogService.open(ModalFormComponent);
}
我在浏览器控制台中看到了这个错误:
ERROR Error: No component factory found for ModalFormComponent. Did you add it to @NgModule.entryComponents?
at noComponentFactoryError (core.js:19453)
at CodegenComponentFactoryResolver.resolveComponentFactory (core.js:19504)
at NbPortalOutletDirective.attachComponentPortal (portal.js:506)
at NbDialogContainerComponent.attachComponentPortal (index.js:17128)
at NbDialogService.createContent (index.js:17336)
at NbDialogService.open (index.js:17295)
at SearchBarComponent.openAddDialog (search-bar.component.ts:46)
at Object.eval [as handleEvent] (SearchBarComponent.html:11)
at handleEvent (core.js:34777)
at callWithDebugContext (core.js:36395)
您认为问题出在哪里,以及我该如何解决它?