registerBackButtonAction working on many views

For a view X I have a controller called ControllerX.

Here is a snippet from controllerX to listen to hardware back button event:

$ionicPlatform.registerBackButtonAction(someFunc, 100);

Now the problem is when I navigate to any other page or view from view 'X' then any events on hardware button on the new page still responds by executing someFunc that I had defined and used in ControllerX.

How should I remove that response for all my views except view X

@mhartington Where are you?

I see similar behavior. I have an issue with closing a modal upon executing the back button. I placed a dummy do nothing function in my controller and registered it using

$ionicPlatform.registerBackButtonAction(someFunc, 100);

Because the function does nothing, the back button is completely disabled in the app, even exiting the app.

Sorry for necro this post, but i’m going to implement that functionality in my app and i think that the solution could be in this link http://ionicframework.com/docs/api/service/$ionicPlatform/

The same way you bind the event to the HardBackButton, you can remove the eventlistener when changing states.

var deregister = $ionicPlatform.registerBackButtonAction(
            function () {
                console.log("close the popup")
            }, 100
    );
    //Then when this scope is destroyed, remove the function
    $scope.$on('$destroy', deregister)

Store your back button registration in a variable -> destroys the function if the view gets destroyed.