Unable to open ModalController with lazy loading ionic

I’m implementing lazy loading in my ionic 3/angular5 app in order to boost performance. But I’m unable to open a modal using it and it drives me crazy. I have a page (Journal in red) where I load messages and display them (message-item in green). When the user click on it, it open the full message (MessageModal in blue) on a modal like below.

enter image description here

I created 3 separate modules for each of them. But I keep getting the following error after a tap on the button OPEN MESSAGE although I added the MessageModal to the message-item module :

Uncaught (in promise) : Error : No component factory found for
MessageModal. Did you add it to @NgModule.entryComponents

So I tried to add the ModalMessage to entryComponents to each modules/components but it still doesn’t work and I’m really stuck.

JournalModule should need to import the MessageModule and MessageModalModule and MessageModule should add MessageModal to its entryComponents. Please find the code below :


  declarations: [ JournalPage  ],
  imports: [
  providers: [JournalService], 
  exports: [JournalPage],
  entryComponents :[MessageModal]
export class JournalPageModule {}

Piece of journal.html

 <ion-list *ngIf="messages.length !=0 && messageLoaded == true">
          <message-item *ngFor="let message of messages" [message]="message"  (quizz)="handleQuizzResult($event)"  (delete)="deleteMessage($event)" (isRead)="messageRead($event)" ></message-item>


  declarations: [ MessageItem ],
  entryComponents : [MessageModal],
  imports: [ IonicPageModule.forChild(MessageItem)],
  exports : [MessageItem]
export class MessageModule {}

Piece of message.ts

   selector: 'message-item',
   templateUrl: './message.html',
   entryComponents : [MessageModal]


let modal = this.modalCtrl.create( MessageModal, { message : this.message });


  declarations: [ MessageModal ],
  imports: [ IonicPageModule.forChild(MessageModal)],
  exports : [MessageModal]
export class MessageModalModule {}

I don’t know where am i wrong… Any advices/docs appreciated !

I’m not sure about which piece of code is your modal and which piece of code isn’t…so here’s my code for a modal:


   templateUrl: 'my-modal.html',
   selector: 'my-modal'
export class MyModal {


declarations: [
imports: [
export class MyModalModule {

that’s it, nothing more.

IMPORTANT to call your modal, don’t forget to not use the class name (which is probably your typing mistake according the code you display above) but to give the name of your class as a string

 let modal:Modal = this.modalController.create('MyModal'); // <-- Good
 let modal:Modal = this.modalController.create(MyModal); // <-- Bad for lazy loading

Blockquote let modal:Modal = this.modalController.create(‘MyModal’); // <-- Good
let modal:Modal = this.modalController.create(MyModal); // <-- Bad for lazy loading

Thank you very much!!!

1 Like