Tutorial to learn about Hardware Back Button


#1

Can someone make a tutorial about how to use and implement hardware back button. I am not talking about just plain implementation of the back button like this:

$ionicPlatform.registerBackButtonAction(function(){ 
    //some action
}, 100);

But for something deeper into back button like how to implement different back button actions for different pages and how to remove and change back button action for certain pages etc.


When can we expect standard mouse events as directives
#2

Alright, so finally I’m able to answer this. Took a while, but here’s whats going on. So when you register that function, you need to deregister that function after changing views.

RegisterBackButtonAction returns a deregister function to allow this.

            var deregister = $ionicPlatform.registerBackButtonAction(
                    function () {
                        alert("Show on the home page")
                    }, 100
            );
            $scope.$on('$destroy', deregister)

So after you change your view, this will clean up that action :smile:


#3

Why is that not their in the docs? :rage3: I opened ionic-bundle.js and saw the ‘destroy’ function on back button but without proper docs I was not able to do it.


#4

This is true, our docs aren’t always perfect. You can make a PR to expand the description of the register back button.

https://github.com/driftyco/ionic/blob/master/js/angular/service/platform.js#L51


#5

Thanks mhartinton: it is working fine with your suggestion