I am trying to disable hardware back button on android device when $ionicModal
is open.
$ionicModal.fromTemplateUrl('templates/dashboard.html', {
scope: $scope,
hardwareBackButtonClose : false
}).then(function(modal) {
$scope.modal = modal;
$scope.modal.show();
});
I am using following $ionicPlatform.registerBackButtonAction
method for handle back button in app.js
$ionicPlatform.registerBackButtonAction(
function(event) {
if(navigator.connection.type != Connection.NONE) {
if ($ionicHistory.currentStateName() == "app.dashboard") {
if (localStorage.getItem('token') !== null
&& localStorage.getItem('token') !== undefined
&& localStorage.getItem('token') !== ''
&& $rootScope.userId !== undefined) {
$rootScope.confirmExitPopup = $ionicPopup.show({
templateUrl : 'Views/ConfirmationPopup.html',
title : 'demo',
cssClass: 'customfilter-popup',
});
$rootScope.onSuccessPopup = function(){
ionic.Platform.exitApp();
$rootScope.confirmExitPopup.close();
}
$rootScope.closePopup = function () {
$rootScope.confirmExitPopup.close();
};
} else {
$ionicHistory.goBack();
}
} else {
if($ionicHistory.backView()){
$ionicHistory.goBack();
}
else{
$state.go("app.dashboard");
}
}
}
else{
ionic.Platform.exitApp();
}
}, 1000);
When my $ionicModal
is open then I click the hardware back button
$ionicModal
is not close but state is changed so I want to disable hardware back button when my $ionicModal
is open. I have already added hardwareBackButtonClose : false
property in $ionicModal
but its override by $ionicPlatform.registerBackButtonAction
method.
how to disable it? Thank you.