Two modals and modal.shown event


#1

Hello!

I have two modals ( new and edit ):

.controller('CustomFilterCtrl', function($scope, .... and other params) {
    
    $ionicModal.fromTemplateUrl('templates/customFilter-new.html', function(modal) {
	$scope.newCustomFilterModal = modal;
    }, {
	animation: 'slide-in-up',
	focusFirstInput: true
    });

    $ionicModal.fromTemplateUrl('templates/customFilter-edit.html', function(modal) {
	$scope.editCustomFilterModal = modal;
    }, {
	animation: 'slide-in-up'
    });

}

and a controller for each modal defined from the view:

<ion-modal-view ng-controller="CustomFilterNewCtrl" class="slide-in-up">

and

<ion-modal-view ng-controller="CustomFilterEditCtrl" class="slide-in-up">

In each controller i have the $on(‘modal.shown’) function.

In the CustomFilterNewCtrl:

$scope.$on('modal.shown', function() {
	// actions for the new modal
});

and in the CustomFilterEditCtrl:

$scope.$on('modal.shown', function() {
	// actions for the edit modal
});

Problem: both the functions are executed when I open one of the modal! How can i fire the modal.shown on a specific modal?

Thanks


#2

Hello,

Yes, this is the behavior of modals. If you have two modals they each receive events.
For handling the correct modal event you can write an if statement like this one:

$scope.$on('modal.shown', function() {
    if($scope.modal1.isShown() && !$scope.modal2.isShown()){

    }
}

#3

Thank you very much! It worked!