Timer From Parent To Modal

I am developing a quiz app and it has a timer. There is a long paragraph which I put in a modal to have a neat layout, I added a button and upon clicking it, a modal opens to show that long paragraph. Now, the timer works in the parent page and not on the modal. How will I dismiss the modal the modal automatically when the timer runs out? Any idea? TIA.

The parent page has a reference to the modal on which it can call dismiss(), so something like this should work:

let modal = this.modals.create(MyModal);
modal.present();
setTimeout(() => {
  modal.dismiss();
}, 3000);

Thanks. I already resolved it by dismiss() inside my timer and when the timer runs out, it will check if the modal is present before calling the dismiss() to prevent “undefined” this.modalTestPage error because there are some instances that the user might not click the button to show the modal:

if(typeof this.modalTestPage != “undefined”) {
this.modalTestPage.dismiss();
}

because I have loaded it in a separate function:

openModalTestPage(info) {
this.modalTestPage = this.modal.create(‘ModalTestPage’, {info: info});
this.modalTestPage.present();
}

Cheers!!!

I think that’s a mistake. When you store things like modals, which cannot be safely either doubly disposed or reused, in object properties, you are just asking for bugs. I would advise concentrating all interaction with this modal in a single function and making it a lexically scoped variable instead of an object property.

To show a modal, a user clicks a button while the timer is running. The function for opening a modal is different from the timer function. The button that has been clicked is just a part of one question of the app. The app has many questions and the timer is not just for one question but for all.