Event after Modal show


#1

I need run some code after Modal show,
how can I catch the event ?

thanks.


#2

Hi,

From http://ionicframework.com/docs/api/controller/ionicModal/

Note: a modal will broadcast ‘modal.shown’ and ‘modal.hidden’ events from its originating scope, passing in itself as an event argument.

$scope.$on('modal.shown', function() {
  console.log('Modal is shown!');
});

#3

Thanks rdelafuente !

but if I got more than one modal,
how can I figure which one is opening ?

thanks.


#4

Hi @jasonshow!

I understand your scenario. What you can do is assign an ID to your modals and use that ID in the broadcasted messages to identify which modal is being shown / hidden / removed.

$ionicModal.fromTemplateUrl('modal-1.html', {
    id: '1', // ID to identify the modal that is firing the event
    scope: $scope,
    animation: 'slide-in-up'
}).then(function(modal) {
    $scope.oModal1 = modal;
});

Take a look at this basic example with two modals: http://codepen.io/rdelafuente/pen/axeph

Hope it helps!


#5

Thanks rdelafuente !
everything is cool now !


#6

saved my day. thanks!