registerBackButtonAction working on many views


#1

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


#2

@mhartington Where are you?


Use Android hardware back button to go back to previous slide in a slidebox
#3

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.


#4

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.


#5
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.