modalInstance.result.finally(function(){
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'); });
source share