Ionic 2 modal dismiss with parameter on Android Hardware Back button

I have a modal which returns data on dismiss. But I want the modal to dismiss on Android Hardware back button. The problem is, on dismissing from hardware back button, no data is returned and onDidDismiss() method is not called. Is there a way to achieve this?



That only covers if you’re calling the dismiss(data, role , NavOptions) function directly (e.g. if you have your own back button). But, if they’re using the hardware back button (or just clicking outside the modal to automatically dismiss it) you never have any opportunity to set the data property of the dismiss method – it’s just automatically called for you without any data property :frowning:


I am currently looking for a solution to this also. I have hooked into the ionViewWillLeave call, to then call my own version of dismiss. The previous page does get the data, but then crashes immediately after with a runtime error of Uncaught (in promise): false.

If I could figure a way to stop the auto dismiss process, so that the new manual call works. Hmm…

I think I answered this for you on another thread, but you could just save to local storage instead of playing around with viewControllers and navParams.

1 Like

If we were to go down the route of using IonicStorage to transmit data our throughout the app, it would make for a fairly poor development experience. Not to mention the aspect of waiting for async access to the localstorage to fetch/set the data. I’d rather work as closely to what the Ionic devs have implemented for us, than hacking on an approach


??? Storage is stable, while routing is a work in progress. You’re describing an approach that puts you at risk of breaking changes, while telling me it’s what the devs have implemented.

I’ve been passing data from page to page via navParams since March of last year, seems fairly stable.

I don’t think HTML5 LocalStorage (rather than IonicStorage) is async. Totally hadn’t thought of that; thanks @AaronSterling (though Ionic, you really should have a better solution than this)

You’re reporting a problem because a problem exists, right?

Another solution occurs to me: you could create a tiny Redux service, and put the information there. Part of the reason I started using Redux was so data would be available “no matter what” the user or the device did. It’s eliminated almost all these “pass information from page A to B” type issues.