Call callback function on esc in Angular UI Bootstrap's modal

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?

Answers


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();
});

Need Your Help

Best non-flash upload component for web applications?

javascript jquery upload

I would like recommendations for upload scripts/components. My criteria: