Make a back button a logout button

Hi,

I am currently working my back button. And i am wondering how can I convert one one of my back button into a logout button. I need to add a ng-click and have my function to do what I need for my logout so my real question would be :

How can I prevent my new “logout button” to prevent backing out if a cancel button is pressed?

This is my back button at the moment, like I said I still need to add a function for my logout fonction.


          
            
          
    

Thank you! I hope I am clear! :slight_smile:

Hi,
Since you are using ionic you can use $ionicPlatform.registerBackButtonAction inbuilt function.
See this example… Hope this helps.

$ionicPlatform.registerBackButtonAction(function (e) {
e.preventDefault();
function showConfirm() {
var confirmPopup = $ionicPopup.show({
title: ‘Logout…’,
template: ‘Are you sure you want to logout?’,
buttons: [{
text: ‘Cancel’,
type : ‘’,
}, {
text: ‘Ok’,
type : ‘button-calm’,
onTap: function () {
// write your code for logout here…
}
}]
});
};
if ($ionicHistory.backView()) {
$ionicHistory.backView().go();
} else {
showConfirm();
}
return false;
}, 101);

1 Like

it clarifies things. Thank you

I found something that helped understand a bit more how it was done .

look at this answer :