Next issue: I have a slider inside a template. The back button navigates you out of the template. The desired behavior is that the back button backs you up through the slides until the first slide, then out of the template.
This is where I think the use of registerBackButtonAction() will come in.
Is there a way to de-register the function without replacing it with a dummy function? Also, it seems that the registerBackButtonAction() applies to the entire app. I thought that I read somewhere that it could be restricted to the controller.
This may not be the appropriate topic and I should create a new one.
If you want to de-register the custom back button action, you would set this up.
var deregister = $ionicPlatform.registerBackButtonAction(
function () {
console.log("I did something")
}, 1
);
//Then when this scope is destroyed, remove the function
$scope.$on('$destroy', deregister)
My goal is to use the back button to navigate back through the slides until the first slide, then de-register the BackButtonAction (and let the normal back navigation take over). Everything works fine until the first slide, but you have to hit the back button twice for it to work.
I am assuming that the first back is consumed with the de-register action and therefore the second is the actual back under normal navigation.
Therefore, I need to create a second back action within the de-register or somehow allow propagation to occur. Thoughts?
var deregister = $ionicPlatform.registerBackButtonAction(
function () {
console.log("registerBackButtonAction");
if ($ionicSlideBoxDelegate.currentIndex() == 0) {
console.log("deregister");
deregister();
} else {
console.log("registerBackButtonAction previous");
$scope.previous();
}
}, 100
);
// Then when this scope is destroyed, remove the function
$scope.$on('$destroy', deregister);
// Slide navigation methods
$scope.next = function() {
$ionicSlideBoxDelegate.next();
};
$scope.previous = function() {
$ionicSlideBoxDelegate.previous();
};
This does break my previous solution to close the modal using the following:
scope.$on(â$destroyâ, function () {
console.log(âclose the popupâ);
âŚ
$ionicBackdrop.release();
});
Under normal back navigation, the template is destroyed. With the registerBackButtonAction code, navigation occurs within the slidebox and the directives destroy is not called.
var deregister = $ionicPlatform.registerBackButtonAction(
function () {
console.log("registerBackButtonAction");
if ($ionicSlideBoxDelegate.currentIndex !== 0) {
//If the current slide index doesn't equal 0,
//we'll let the slides go back
$scope.previous();
} else {
//Nothing should be done, so let the default behavior take over
}
}, 100
);
// Then when this scope is destroyed, remove the function
$scope.$on('$destroy', deregister);
I tried it with no luck. The back portion works fine, but back button doesnât do anything on the first slide. The âNothing should be done, so let the default behavior take overâ else condition is still intercepting the back event.
The $scope.$on(â$destroyâ, deregister); does happen because you can never leave the template.
It seems that the registerBackButtonAction() consumes the action.
Iâm having a similar issue but on a Web App⌠As far as I could analyse, the $IonicPlatform backbutton doesnât capture anything if itâs a web app.
StateChange start also doesnât work if thereâs nothing in the history stack (closes the app if pressed)
Any ideas on how to enable close of the modal on backbutton press if on a web app ? Itâs seems to work fine on the native appâŚ