No component factory found for DialogNamePromptComponent. Did you add it to @NgModule.entryComponents?
我有这个文件
bar-chart-card.component.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import { NgModule } from '@angular/core'; import { Component } from '@angular/core'; import { NbMenuService, NbSidebarService } from '@nebular/theme'; import { NbDialogService } from '@nebular/theme'; import { filter, map } from 'rxjs/operators'; import { DialogNamePromptComponent } from './detail-view.component'; @Component({ selector: 'ngx-bar-chart-card', templateUrl: './bar-chart-card.component.html', styleUrls: ['./bar-chart-card.component.scss'] }) export class BarChartCardComponent { flipped = false; cardSettingCtxMenu = [{ title: 'Profile' }, { title: 'Log out' }]; constructor( private dialogService: NbDialogService, private menuService: NbMenuService) { } ngOnInit() { console.log("asasas"); this.menuService.onItemClick() .pipe( filter(({ tag }) => tag === 'my-context-menu'), map(({ item: { title } }) => title), ) .subscribe(title => this.open3()); } toggleView() { this.flipped = !this.flipped; } open3() { console.log("================"); this.dialogService.open(DialogNamePromptComponent); } } |
detail-view.component.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import { Component } from '@angular/core'; import { NbDialogRef } from '@nebular/theme'; @Component({ selector: 'ngx-detail-view', templateUrl: './detail-view.component.html' }) export class DialogNamePromptComponent { constructor(protected ref: NbDialogRef<DialogNamePromptComponent>) {} cancel() { this.ref.close(); } submit(name) { this.ref.close(name); } } |
e-commerce.module.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import { BarChartCardComponent } from './bar-chart-card/bar-chart-card.component'; import { DialogNamePromptComponent } from './bar-chart-card/detail-view.component'; @NgModule({ imports: [ ThemeModule, ChartModule, NgxEchartsModule, NgxChartsModule, LeafletModule, ], declarations: [ DialogNamePromptComponent, BarChartCardComponent ], providers: [ CountryOrdersMapService, ], entryComponents: [BarChartCardComponent,DialogNamePromptComponent] }) export class ECommerceModule { } |
在这里,当我调用方法
No component factory found for
DialogNamePromptComponent . Did you add it to@NgModule.entryComponents ?
通常,您需要将将动态构造的任何组件添加到模块定义中的entryComponents数组中。
1 2 3 4 5 6 7 | @NgModule({ providers: [...], declarations: [...], entryComponents: [DialogNamePromptComponent, ... ], ... }) export class YourModule { } |
这在Nebular的文档中没有指定,但是我认为他们使用的是Angular的ComponentFactoryResolver,如果没有在其他地方加载该组件,则需要此。
但是,我注意到您为BarChartCardComponent类的组件装饰器错误地添加了NgModule装饰器,这是我以前从未见过的。据我所知,一个类不能同时是一个组件和一个模块。因此,删除该NgModule装饰器。
将DialogNamePromptComponent添加到父模块的entryComponents
1 2 3 4 5 6 | @NgModule({ declarations: [DialogNamePromptComponent], entryComponents: [ DialogNamePromptComponent ], }) |