3

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."

3 Answers 3

7

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

Try as follows.

const modal = await modalController.create({ component: UploadPage });
const { data } = await modal.onDidDismiss();
if (data) {
   this.getData();
}
3

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.

1

As per official document :

const modal = await modalController.create({...});
const { data } = await modal.onDidDismiss();
console.log(data);

See official docs link

Not the answer you're looking for? Browse other questions tagged or ask your own question.