结束事件后的角度ui模态 [英] angular ui modal after close event
问题描述
有没有一种方法可以在调用模式窗口后调用函数(无论它是通过按钮发生还是通过单击背景而发生)
Is there a way I can call a function after a modal window got called (no matter if it happened with a button or by clicking on the backdrop)
var dialog, options;
options = {
windowClass: "lightBox"
templateUrl: "url to the template",
controller: "some random controller",
scope: $scope
});
$("body").css({
'overflow': 'hidden'
});
dialog = $modal.open(options);
dialog.result.then(function() {
$("body").css({
'overflow': 'auto'
});
});
我希望每次模态窗口关闭结果中的函数后,然后保证执行.现在,当我手动关闭$ modalInstance.close()模态时,它才执行.但是,如果我在背景上单击,则不会调用此方法
I want that everytime the modal windows closes the function in the result.then promise get executed. Now it just executes when i close the modal manually my $modalInstance.close(). But if i click on the backdrop this method doesn't get called
知道我该怎么做吗?
推荐答案
我假设您正在使用angular-ui的模态"对话框.但是在进入细节之前,需要一些有关AngularJS中的Promise的文档.您需要知道每个 then 函数都可以接受3个参数,例如:
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 . 当拒绝承诺时,会执行
- errorCallback . 收到通知时执行
- notifyCallback .
- successCallback is executed when the promise is resolved.
- errorCallback is executed when the promise is rejected.
- notifyCallback is executed when notified.
对于angular-ui的模态,单击背景将导致被拒绝的承诺.考虑到这一点,您的代码可以更改为:
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());
});
您可以在此处
这篇关于结束事件后的角度ui模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!