There are questions about overriding the physical Android BACK button in Ionic, to provide custom behaviour:
- Ionic override all BACK button behaviour for specific controller
- Ionic: How to override back button function?
But how do you cancel the override to restore default behaviour?
I have tried changing the priority of the handler, in the hope that a default handler may have a higher priority.
var customBackButton = function() {
console.log("this is custom behaviour");
};
$ionicPlatform.registerBackButtonAction(
customBackButton, 101
);
$scope.$on('$destroy', function() {
$ionicPlatform.registerBackButtonAction(
customBackButton, 0
);
});
This does not work.
Ionic v1 solution (out of date)
According to the Ionic docs for
$ionicPlatform
, theregisterBackButtonAction()
returns:This can be seen in the code for
registerBackButtonAction()
:So the correct way to deregister / cancel the custom behaviour is to call that function when the controller is destroyed:
A more complete example showing how to override & restore the hard and soft buttons can be found here: