Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return values from ionic2 modal to parent page

Tags:

ionic2

I am opening a Modal in ionic2, to search the values from a list. After search, I want to get the selected values back in my parent screen.

searchRooms(){
    let modal = this.modalCtrl.create(RoomSearch);
        modal.present();
  }

This opens my search Modal and there I have list of available rooms. If user click on any room then I want to return back the value to parent page. I am not sure how to do this.

From documentation I feel NavConroller.pop can be used to pass back the values but I don't know how to use that.

Thanks in advance.

like image 926
amyst Avatar asked Nov 26 '16 10:11

amyst


1 Answers

You can use onDidDismiss method explained in the Modal Controller.

In the page that opens your modal you can do :

let modal = this.modalCtrl.create(RoomSearch);

modal.onDidDismiss(data => {
    // Do things with data coming from modal, for instance :
    console.log(data);
});

modal.present();

And this in your modal controller, to close the modal :

this.viewCtrl.dismiss({"foo" : "bar"});
like image 157
Hadrien TOMA Avatar answered Nov 11 '22 21:11

Hadrien TOMA