I'm using a modal of Angular UI Bootstrap that can be closed via a Cancel button or via ESC. As I have to do some cleaning when it closes, I've written the 'cancel' method in the scope, but this is only called when clicking this Cancel button, how could I do to call this cleaning functions when it closes on ESC too?
When a modal is dismissed (either by pressing ESC or clicking on backdrop) a promise returned from the $modal.open
method call is rejected. So you can react on ESC press by adding error handler to the returned promise. This is illustrated in the example available from the demo page: http://plnkr.co/edit/xMTr78WJQbKyHsA53gyv?p=preview
(see this line: $log.info('Modal dismissed at: ' + new Date());
)
thanks @pkozlowski.opensource
i directly knew what to do :)
var modalWindow = $modal.open({
windowClass: 'modal myKewlDialog',
templateUrl: 'views/modals/myKewlModalTemplate.html',
controller: 'myKewlModalController'
});
modalWindow.result.then(function (result) {
updateUI();
}, function (result) {
updateUI();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With