Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to a call function after dismiss the Modal in Ionic 4

I am using modal and want to call a function after dismiss the modal.

i have tried onDidDismiss() method but it shows an error

async openModal() {
    const modal = await this.modal.create({ component: UploadPage });
    modal.onDidDismiss(() => {
        this.getData();
    });
    return await modal.present();
}

getData() {
......
}

in this way i got an error "Expected 0 arguments, but got 1."

like image 690
Aashish Chakravarty Avatar asked Sep 18 '25 09:09

Aashish Chakravarty


2 Answers

onDidDismiss() returns Promise<OverlayEventDetail<any>>.

Try as follows.

const modal = await modalController.create({ component: UploadPage });
const { data } = await modal.onDidDismiss();
if (data) {
   this.getData();
}
like image 147
Sudarshana Dayananda Avatar answered Sep 20 '25 23:09

Sudarshana Dayananda


As other answers stated, now onDidDismiss() also returns a promise. So you can follow how documentation advises you to capture data or do something like this, its just another syntax basically:

async openModal() {
    const modal = await this.modal.create({ component: UploadPage });
    modal.onDidDismiss().then((data) => {
        console.log(data)
    });
    return await modal.present();
}

actual data will be inside data.data in this case.

like image 24
Sergey Rudenko Avatar answered Sep 20 '25 23:09

Sergey Rudenko