I am facing an issue how to handle the default mobile's back button which checks the confirmation while exiting from the application, if I pressed the back button there should invoke some handler which shows pop-up, for confirm exiting. OR there is any method call registerBackButtonAction()? or is it so how to use it in IONIC 2,? Please help me out. Thanks in Advance.
相关问题
- Angular RxJS mergeMap types
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
Platform api has a handler
registerBackButtonAction
.You can do something like:
In app.component.ts
Kinda late to the party... But there is more to back button other than closing the pushed pages, specially for project with several tab pages.
Sometimes a page is pushed NOT into the root page, but in one of the tab page's navCtrl. So we have to check for all of them.
Also, if no page or menu is open, we should circle around the most recently used tabs (similar to Instagram app) and go back to the previous tab. Moreover, we should not go back to each tab more than once (similar to Instagram)
I got inspired by the answers here and created a comprehensive method that handles all necessary features:
The details are in this blog post
A demo code can be downloaded from my github.
In app.component.ts
Html:
TypeScript:
I managed to create this function by doing a lot of research. Hope it helps.
activePortal can be used to find the relevant active portals which includes alert, loader, modal, etc. If you want to handle everything with the back button or some of them uncomment according to your usage
In my case I only wanted to check if modal was active so I checked only for modal.
Ionic latest version 3.xx
app.component.ts
file: