Make a back button a logout button


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:

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

$ionicPlatform.registerBackButtonAction(function (e) {
function showConfirm() {
var confirmPopup = ${
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()) {
} else {
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 :