How to return value from modal


is there a way to return a value from a modal?

I have a modal with search component implemented selected value should be returned and modal closes, i have done the closing part but no idea how to get that value.

Did anyone done this?


If you save that value in the $scope it should stick even with the modal closed. Did you try?

can we use $scope in angular 2?

My bad, I didn’t notice you were talking about angular2. No idea then :confused:

This might help you.

Thanks Richard, i will definitely going to look into this.

You could always use a shared service to store data in, the solution Richard mentioned is probably better for most cases.

This will be added in the alpha.38 release which I plan on doing later today, you will be able to pass data back in the close function:

In the close function of the modal page:

  closeModal() {
      adel: 'hello',
      lionel: 'hello'

In the function opening the modal from the main page:

  openToolbarModal() { => {
      // modal has finished opening
      // modalRef is a reference to the modal instance
      modalRef.onClose = (modalData) => {
        // somehow modalRef.close(modalData) was called w/ modalData
        console.log('modalRef.onClose', modalData)

When this is released I’ll be adding an example to the conference app, as well.

1 Like

Up! :slight_smile:
At now, I can return data throw dismiss method. But, I don’t understand how I can catch this data?

PS: Please. fix docs :worried:

Once you’ve created your modal, add an onDismiss listener before presenting it on the nav, i.e:

myModal.onDismiss(data => {

Please note that the method was renamed to onDidDismiss:

let profileModal = this.modalCtrl.create(Profile, { userId: 8675309 });
profileModal.onDidDismiss(data => {

( )