AngularJS: function call when modal closes

I assume this is a fairly simple answer, but I cannot find the correct syntax.

I have a modal discovery like

$scope.assignment = function (groupId) { var modalInstance = $modal.open({ templateUrl: 'assignment_form', controller: 'GroupsAssignmentController', windowClass: 'modal-user-window', resolve: { id: function () { return groupId; } } }); 

All I want to do is run the function when the modal is closed, so my main screen is updated.

I'm not sure if this is related to $ modal.close?

  $modal.close({ //getAllGroups(); }); 
+5
source share
1 answer
 modalInstance.result.finally(function(){ // do your work here }); 

You can also use

 then(successCallback, errorCallback, notifyCallback) 

SuccessCallback stands out when the promise is resolved. errorCallback is executed when the promise is rejected. Finally, notifyCallback is executed upon notification.

In the case of angular -ui, modal clicking on the background will reject the promise. With this in mind, your code can be changed to:

 modalInstance.result.then(function () { alert('Modal success'); }, function () { alert('Modal dismissed'); }); 
+6
source

All Articles