Ionic Modal don't return data. How to return data from ionic modals?

You need to add a handler for modal’s onDismiss() and then return the data from the modal itself by passing the data to the ViewController’s dismiss() method:

// myPage.ts
// Passing data to the modal:
let modal = Modal.create(myModal, { data: [...] });

// Getting data from the modal:
modal.onDismiss(data => {
    console.log('MODAL DATA', data);
});

this.nav.present(modal);
// myModal.ts
constructor(inputData: NavParams, private view: ViewController) {
    // Getting data from the page:
    var dataFromPage = inputData.get('data');
}

dismiss() {
    // Returning data from the modal:
    this.view.dismiss(
        // Whatever should be returned, e.g.:
        // { ... }
    );
}
18 Likes