Patrick Patrick - 4 months ago 23
jQuery Question

Execute function when modal is closed (Plunker attached)

I have a minor bug which i am not able to fix. Here is the plunker-> http://plnkr.co/edit/D3EjXKf48Sq2vuc5MHNx?p=preview

When the user opens the modal and makes selection, he chooses to close the modal by pressing 'Ok'

At this point of time, i want to execute ExecOnModalClose() function mentioned in the controller.

So, here is the code i tried.

$scope.ok = function() {
$uibModalInstance.close();
$scope.ExecOnModalClose();
};


Execute this function below when user presses 'Ok' as shown above.

$scope.ExecOnModalClose = function() {
console.log("Execute this after modal closes on pressing Ok");
}


Can someone please let me know how to link these two.

Answer

You can use

<button class="btn btn-primary" type="button" ng-click="ok(); ExecOnModalClose()">OK</button>

EDIT

after the change of the original plunker, using broadcasting seems to be the working solution: http://plnkr.co/edit/0ZrOM2au5wErWfUtX4v4?p=preview