Angular 未找到DialogNamePromptComponent的组件工厂。您是否将其添加到@NgModule.entryComponents?

Angular 未找到DialogNamePromptComponent的组件工厂。您是否将其添加到@NgModule.entryComponents?,angular,nebular,Angular,Nebular,我有这个档案 条形图卡片.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 }

我有这个档案

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

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

}
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);
  }
}
    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 { }
在这里,当我调用method
open3
时,我得到了以下错误:

未找到
对话框NamePromptComponent
的组件工厂。您是否已将其添加到
@NgModule.entryComponents


将对话框名称PromptComponent添加到父模块入口组件中

@NgModule({
  declarations: [DialogNamePromptComponent],
  entryComponents: [
  DialogNamePromptComponent
],
})

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

@NgModule({
    providers: [...],
    declarations: [...],
    entryComponents: [DialogNamePromptComponent, ... ],
    ...
})
export class YourModule { }
这在Nebular的文档中没有详细说明,但我假设他们使用Angular的ComponentFactoryResolver,如果组件没有加载到其他地方,则需要这个


然而,我注意到您在类BarChartCardComponent的组件decorator前面错误地使用了NgModule decorator,这是我以前从未见过的。据我所知,类不能同时是组件和模块。因此,请卸下该模块装饰器。

然后。。。您是否将其添加到@NgModule.entryComponents?这是否回答了您的问题?即使这样做了,我还是更新了我的问题