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


How to return data from ionic 2 modals?

SCENARIO: I need that user select any item of an Array of items (it’s ok, i’m passing this data to list in modal), after select this item, the created modal must be closed and return this selected item.

I’m trying the follow code…

let modal = Modal.create(myModal, {data: […] });
modal.onDismiss(data => {
console.log(‘MODAL DATA’, data); // returns “undefined”


Thanks! @mhartington

Add items to a list with a 'Popover' component in Ionic 2

What about calling dismiss instead of onDismiss and then return something? Like this:

modal.dismiss( console.log(data) );

Or if you pass it down through the viewCtrl something like this:
this.viewCtrl.dismiss(console.log(data) );


Thanks @luukschoen, i’ll try this way.


I think the API docs aren’t fully up-to-date. Use the syntax from the component docs, pretty sure it’ll work. I suggest that the API docs are extended with dismiss and onDismiss, or maybe give a hint to whether what’s the difference between the two. It’s not entirely clear now.


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);

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

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

Ionic 2 Passing parameters from a modal with provider
List does not update

@iignatov Perfect! it works!.. Thanks man. @luukschoen thank for your collaboration. This topic may can be useful to others members. :slight_smile:


How did you make it work? Would you be able to post your sample code?


@Deep0802 Check out the sample code in my answer above - basically you have to add a onDismiss-handler for the modal (to get the data) and return the data from the modal itself by using the ViewController's dismiss() method (you pass the data as a parameter to the method).


I was able to figure that out from your code. Thanks for reply!:slight_smile:


Looks like Modal.OnDismiss is Modal.OnDidDismiss now.


what about if user didn’t use my dismiss function ? for example he clicked hardware back button in android devices or he used backdrop to dismiss the modal ?

simply i want to send data to outside whatever the reason that caused to dismiss the modal


Currently looking for a solution for this also. On larger screens it is possible to click/press on the backdrop, which dismisses the modal, but I’m not aware of the method that I can hook into to append some return data.


Can’t you just save whatever data you want to save in local storage while inside ionViewWillLeave() ? The you can collect the information from local storage whenever you want.


Could do yeah, but that’s a bit of a convoluted work around for something that seems 99% of the way there. Just want a simple way to intevene in the dismiss process to add some data. Currently looking at using ionViewWillLeave, to add some data within that hook.


actually i decided send the data from the modal with custom event in ngOnDestroy and listen to that event outside because with any way that the modal dismissed the ngOnDestroy called

so the code will be like this, in the modal class:

 ngOnDestroy() {
        // any data 

and outside the modal should be like this:

let didDismissObservable = events.subscribe('modalDidDismissedEvent', (data) => {

hope that help someone


In modal I kept like below

this.presentToast("Data Updated...");            

but its not working in timeout displaying error dismiss to undefined but without timeout its working


tis is Working

openModal(characterNum) {

let modal = this.modalCtrl.create(ModalContentPage, characterNum);
modal.onDidDismiss(data => {  //on dismiss get data 
  console.log('MODAL DATA', data);; //return data