I will assume that you are using the Modal dialogs from angular-ui. But before going into the details a bit of documentation around promises in AngularJS is needed. You need to know that every then function can accept 3 parameters as such :
then(successCallback, errorCallback, notifyCallback)
- successCallback is executed when the promise is resolved.
- errorCallback is executed when the promise is rejected.
- notifyCallback is executed when notified.
In the case of angular-ui's modal, clicking on the backdrop will result in a rejected promise. With this in mind, your code could be changed to :
dialog.result.then(function () {
alert('Modal success at:' + new Date());
}, function () {
alert('Modal dismissed at: ' + new Date());
});
You can see a working plunker here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…