Recently something happened to my modal (maybe after upgrading to ionic v5) all my modals are now being dismissed right away after they are drawn on the screen. Only the first modal accept user input. I have no idea how to debug this. Following the docs I removed all the my modal components from entryComponents of the modules they are defined but putting them back doesn’t seem to fix it.
What do you mean by “reuse” and don’t do what?. Any modals can to be opened more than once (one at a time) and dismissed when a button is pressed. This has worked flawlessly in previous version and other programs based on ionic. It is just this program and I am trying to understand why and how to debug it.
const modal = await this.modalCtrl.create({ component: MyModalComponent, componentProps: { title: 'my modal' });
await modal.present();
return modal.onDidDismiss().then (result => {
if (result && result.data) {
// do something
}
});
MyModalComponent has a constructor (public modalCtlr: ModalController) and from html
(click)="modalCtrl.dismiss({ something: true })"
MyModalComponent is defined in the declarations: block of a module that I import from other module.
Note that before I was also defining this MyModalComponent in the entryComponents block but I read it is not required anymore with ivy. Regardless putting it back didn’t seem to alter the behavior
Generally, storing a reference to the modal in a page or service property, and attempting to present it after it’s been dismissed once (or trying to dismiss the same modal twice).
Don’t call any methods on a modal once it’s been dismissed. They’re single-use components.