How to catch modal onHide that is closed by backdrop?


#1

I’ve got a modal:

  $ionicModal.fromTemplateUrl('products_modal.html', {
    scope: $scope,
    animation: 'slide-in-up',
    focusFirstInput: false,
    backdropClickToClose: true,
    hardwareBackButtonClose: true
  }).then(function(products) {
     $scope.products = products;
  });

I need to react on the modal close from backdrop or device back button and do something when it happens. I’ve seen in the docs that some events are fired, but I cannot catch them. Here is my code:

  $scope.$on('products.hidden', function() {
       console.log('onModalClose catched!');
       doSomethingOnModalClose();
  });

Unfortunately this doesn’t work for me and the console output never happens.

The above code is inspired by http://ionicframework.com/docs/api/service/$ionicModal/

Could you please point me to a correct solution? TIA.

Cheers,
Rafal


#2

Hi @rafaellop !

Did you get an answer for your own question? I need to catch this event too.

Any help on this, @mhartington ?

Thanks!


#3

So you are trying to catch the modal.hidden event?


#4

Yes, but I’m doing it wrong. :disappointed_relieved:

My old code (doesn’t work):

$ionicModal.fromTemplateUrl('gmaps_legal.html',{
    scope: $scope
}).then(function(modal) {
    $scope.gmapsLegal = modal;
});           

$scope.$on('gmapsLegal.hidden', function(){
    alert('hidden!');
});

Working code:

$ionicModal.fromTemplateUrl('gmaps_legal.html',{
    scope: $scope
}).then(function(modal) {
    $scope.gmapsLegal = modal;
});           

$scope.$on('modal.hidden', function(){
    alert('hidden!');
});

Thanks @mhartington .