How to disable back button with $ionicPopup?

I am showing a popup when user is offline and Currently User can close $ionicPopup using hardware Back button . But I don’t want user to close the popup unless he perform any action.

I tried following but it is not working:

$ionicPlatform.onHardwareBackButton(function (e) {
if($cordovaNetwork.isOffline()) {
e.preventDefault();
return false;
}
})

Anyone having solution to this problem?

Try this:

var deregisterBackButton;
var alertPopup;
$scope.showAlert = function() {
	     
        deregisterBackButton = $ionicPlatform.registerBackButtonAction(function(e){}, 401);
        alertPopup = $ionicPopup.show({
	          ...
        });
	                
        alertPopup.then(function(res) {
	            deregisterBackButton();
        });
};
2 Likes