I'm facing an issue with the Ionic Modal Controller.
In my application, I have a QR modal. I want to handle the case when the backend sends an incorrect QR image. If the image fails to load, the error should be handled, and the modal should close with an error status.
I'm trying to dismiss the modal using this.modalController.dismiss(), but it doesn't work as expected. Sometimes it closes correctly, but other times it closes a previously opened modal. Since multiple modals can be open before the QR modal, dismissing the QR modal shouldn't affect them.
I've created a simple and similar implementation on StackBlitz for you to check.
so in test-dialog.component.ts I try
handleError() { this.close('fail'); } I have also tried something like:
async handleError() { const modal=await this.modalController.getTop() await modal?.dismiss('fail') } but it does not work, only works with setTimeout(() => this.close('fail'), 100) but I dont want to use timeout or delay.
so my guess is race condition in event loop, when image fires error event in modalController modal is not yet registered or something like that, did anyone had simmillar issue?