Manish Kumar
Manish Kumar

Reputation: 10502

No component factory found for DialogNamePromptComponent. Did you add it to @NgModule.entryComponents?

I have this file

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 { }

Here when i call method open3 i am getting this error:

No component factory found for DialogNamePromptComponent. Did you add it to @NgModule.entryComponents?

Upvotes: 1

Views: 721

Answers (2)

Fredrik_Borgstrom
Fredrik_Borgstrom

Reputation: 3258

Normally you need to add any component that will be dynamically constructed to the entryComponents array in your module definition.

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

This is not specified in Nebular's documentation, but I would assume they are using Angular's ComponentFactoryResolver which, if the component hasn't been loaded elsewhere, requires this.

However, I noticed that you incorrectly preceded your component decorator for your class BarChartCardComponent with a NgModule decorator, which is something I have never seen before. To my knowledge, a class can't be both a component and a module at the same time. So, remove that NgModule decorator.

Upvotes: 1

Hassen Fadhlaoui
Hassen Fadhlaoui

Reputation: 187

Add the DialogNamePromptComponent to the Parent module'entryComponents

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

Upvotes: 0

Related Questions