How can i use register Back Button action to call location path?


#1

Hello,

how to use $ionicPlatform.registerBackButtonAction to call $location.path(’/specific-page’) ?

i have tried like this…

var deregister = $ionicPlatform.registerBackButtonAction(function(){ $location.path(’/specific-page’); },100);

but its not working, am i doing something wrong ?

can i register onBackPress event of cordova in controller ?

thank you.


#2

After your $location.path() command, add this line.
$ionicSideMenuDelegate.toggleLeft(false);


#3

Try…

$ionicPlatform.registerBackButtonAction(function(e) {
               window.location = "#/app/Test"; 
or

$state.go('app.Test');
                }, 100);

#4

hello @renjithvincent
first of all, sorry for late reply…
alert(typeof $location) was prompting “undefined” in registerBackButtonAction function.

so i used @shashikant 's code, and at this stage i got three solution

1st = window.location = “#/app/Test”;
2nd = $state.go(‘app.Test’);
3rd = my code as follow

var deregister = $ionicPlatform.registerBackButtonAction(function(event){
        event.preventDefault();
        event.stopPropagation();        
        $state.transitionTo(“profile”);
    },100);

$scope.$on(’$destroy’, deregister);

Thank You.


#5

Hello @jay
Is it working?


#6

Hi i used the following solution…

$state.transitionTo(“profile”);

and i also checked

$state.go(‘profile’);

its also working

thanks