Tutorial to learn about Hardware Back Button

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:

    //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.

1 Like

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:


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.

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


Thanks mhartinton: it is working fine with your suggestion