1
votes

I have tried to lazy-load open a modal in Ionic 5. I have multiple modals to be opened in the same page, so I thought of doing a single function that will open the modal by their string name, given through parameter. It worked on Ionic 3 and also it's written on the ionic 5 documentation. See image below:

The capability to open modals by string name

Here's the code:

async presentModal(modalName: string) {
  const modal = await this.modalCtrl.create({
    component: modalName,
    componentProps: {
      'note': this.massageNote.content
    }
  });
  return await modal.present();
}

The function call:

presentModal('AssessmentSectionModalPage');

When calling the function, here's the error I get.

Error: No component factory found for AssessmentSectionModalPage. Did you add it to @NgModule.entryComponents?

I have also imported the 'AssessmentSectionModalPageModule' in my page's module, but still getting this. Any help? Thanks!

1
Do you add it in imports of app.modupe or page.module? - Mostafa Harb
Yes, already done that. Same error every time. - Emi
If you remove the componentprops will it work? - Mostafa Harb
Tried various ways. Still doesn't work. :( - Emi
I think the way is wrong and i'll test it today and give you an answer, but did you try function or htmlelement? And as i said, will reply after some hours when i reach my computer - Mostafa Harb

1 Answers

0
votes

Same for me, remove componentProps have no efect.