1

我有这个文件

条形图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);
  }

}

详细视图.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);
  }
}

电子商务.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吗?

4

2 回答 2

1

通常,您需要将任何将动态构造的组件添加到模块定义中的entryComponents数组中。

@NgModule({
    providers: [...],
    declarations: [...],
    entryComponents: [DialogNamePromptComponent, ... ],
    ...
})
export class YourModule { }

这在 Nebular 的文档中没有指定,但我假设他们正在使用 Angular 的 ComponentFactoryResolver,如果组件没有在其他地方加载,则需要这个。

但是,我注意到您错误地在类 BarChartCardComponent 的组件装饰器之前使用了 NgModule 装饰器,这是我以前从未见过的。据我所知,一个类不能同时是一个组件和一个模块。所以,移除那个 NgModule 装饰器。

于 2019-06-22T22:49:09.320 回答
0

DialogNamePromptComponent添加到父模块'entryComponents

@NgModule({
  declarations: [DialogNamePromptComponent],
  entryComponents: [
  DialogNamePromptComponent
],
})
于 2019-06-22T22:36:01.670 回答