1

I am using ngx-admin template. Right now i am trying to create a modal that will open on a button click. I am trying to show a form in the modal window but on clicking, the modal does open but it does not show me the form and i get this error

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

I am using lazy laoding and most of the modules have been added in the declaration of a shared.module file to avoid the erros during production. I tried to look at other links too that were available on the stackoverflow but none of them refered to modal-windows/dialogs that's why i had to create this separate thread

classes-and-students.module.ts file

const ENTRY_COMPONENTS = [
    EmailInstructorsComponent
  ];


@NgModule({
    imports: [
        ClassesAndStudentsRoutingModule,
        NbCardModule,
        Ng2SmartTableModule,
         NbAlertModule,
        SharedModule,
        CKEditorModule
    ],
    declarations: [
        ClassesAndStudentsComponent,
        ...routedComponents,
        InstructorbiddingComponent,
        EmailInstructorsComponent,
    ],
    entryComponents: [
        ...ENTRY_COMPONENTS
    ],
    providers: [
        NewsService,
    ],
})
export class ClassesandStudentsModule { }

instructorbidding.component.ts file

@Component({
  selector: 'ngx-instructorbidding',
  templateUrl: 'instructorbidding.component.html',
  styleUrls: ['instructorbidding.component.scss']
})
export class InstructorbiddingComponent {

  @ViewChild('contentTemplate', { static: true }) contentTemplate: TemplateRef<any>;
  @ViewChild('disabledEsc', { read: TemplateRef, static: true }) disabledEscTemplate: TemplateRef<HTMLElement>;


  constructor(private windowService: NbWindowService) { }

  openWindowForm(contentTemplate) {
    this.windowService.open(EmailInstructorsComponent, { title: 'Window'});
  }

}

email-instructors.component.ts file

@Component({
  selector: 'ngx-email-instructors',
  templateUrl: './email-instructors.component.html',
  styleUrls: ['./email-instructors.component.scss']
})
export class EmailInstructorsComponent {

  constructor(public windowRef: NbWindowRef) { 

  }
  close() {
    this.windowRef.close();
  }

}

email-instructors.component.html file

<form class="form">
   <label for="subject">Subject:</label>
   <input nbInput id="subject" type="text">

   <label class="text-label" for="text">Text:</label>
   <textarea nbInput id="text"></textarea>
</form>

I am not sure what mistake i am making so please help me out by pointing out my mistake

Tony Ngo
  • 19,166
  • 4
  • 38
  • 60
Ehsan Nissar
  • 643
  • 2
  • 13
  • 35
  • 1
    Possible duplicate of [Angular 4: no component factory found,did you add it to @NgModule.entryComponents?](https://stackoverflow.com/questions/46990389/angular-4-no-component-factory-found-did-you-add-it-to-ngmodule-entrycomponent) – Nicholas K Jul 29 '19 at 08:55
  • Can you refer the above link and see if any answer resolves your issue. – Nicholas K Jul 29 '19 at 08:56
  • @NicholasK i have already seen this link and it did not solve my issue that's why i created a separate thread for my own code – Ehsan Nissar Jul 29 '19 at 08:59

1 Answers1

2

Try to change your code like this to see if it work

const ENTRY_COMPONENTS = [
    EmailInstructorsComponent
  ];


@NgModule({
    imports: [
        ClassesAndStudentsRoutingModule,
        NbCardModule,
        Ng2SmartTableModule,
         NbAlertModule,
        SharedModule,
        CKEditorModule
    ],
    declarations: [
        ClassesAndStudentsComponent,
        ...routedComponents,
        InstructorbiddingComponent,
        EmailInstructorsComponent,
    ],
    entryComponents: [
        ENTRY_COMPONENTS
    ],
    providers: [
        NewsService,
    ],
})
export class ClassesandStudentsModule { }
Tony Ngo
  • 19,166
  • 4
  • 38
  • 60