我有这个文件
bar-chart-card.component.ts
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
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
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 { }
当我调用方法open3
时,出现此错误:
未找到
DialogNamePromptComponent
的组件工厂。您将其添加到@NgModule.entryComponents
了吗?
答案 0 :(得分:1)
通常,您需要在模块定义的entryComponents数组中添加将动态构建的所有组件。
<head>
<style>
/* style your table here */
</style>
</head>
<table>
<? for (var row in data) { ?>
<tr>
<? for (var col in data[row]) { ?>
<td> <?= data[row][col] ?> </td>
<? } ?>
</tr>
<? } ?>
</table>
这在Nebular的文档中没有指定,但是我认为他们使用的是Angular的ComponentFactoryResolver,如果没有在其他地方加载该组件,则需要此。
但是,我注意到您为BarChartCardComponent类的组件装饰器错误地添加了NgModule装饰器,这是我以前从未见过的。据我所知,一个类不能同时是一个组件和一个模块。因此,删除该NgModule装饰器。
答案 1 :(得分:0)
将 DialogNamePromptComponent 添加到父模块'entryComponents
@NgModule({
declarations: [DialogNamePromptComponent],
entryComponents: [
DialogNamePromptComponent
],
})