0
votes

According to the documentation (http://ionicframework.com/docs/api/controller/ionicModal/), the default behaviour is to close the current modal on back button. But it's not closing anything, instead, it performs the action of the main view, go back.

{boolean=} hardwareBackButtonClose: Whether the modal can be closed using the hardware back button on Android and similar devices. Default: true.

Here is my code when I initialize the modal:

$ionicModal.fromTemplateUrl('app/components/contacts/views/contacts.selectModal.html', {
    scope: $scope,
    animation: 'slide-in-up',
    hardwareBackButtonClose: true
}).then(function(modal) {
    $scope.contactSelect = modal;
});

I'm using Android 5.1, Ionic 1.2.1

1
this might be helpthe_mahasagar
Well, I haven't had any luck with it. Thanks anyway!Mathius17

1 Answers

0
votes

Use $ionicModal option isShown() for recognize modal is open and close on tap hardwareBackButton

Work for me in Android Api 16

$ionicPlatform.registerBackButtonAction(function (event) {           
    if(vm.modal.isShown()) {
      backModal();
    } else {
      window.history.back();
    }

 }, 999);