模态关闭后捕获Angular Bootstrap UI $ uibModal关闭事件 [英] catching Angular Bootstrap UI $uibModal closed event after the modal was closed

查看:522
本文介绍了模态关闭后捕获Angular Bootstrap UI $ uibModal关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来自另一个控制器的$ uibModal.open打开一个模态窗口,需要在模态窗口完全关闭时通知(而不是在关闭期间...)所以我将能够运行一个函数。

I'm opening a modal window using $uibModal.open from another controller, and need to be notified when the modal window was closed completely (and not during closing...) so I'll be able to run a function.

打开模态的代码如下:

var modalInstance = $uibModal.open({
  templateUrl: "myModalContent.html",
  controller: "termModalCtrl",
  windowClass: 'app-modal-window',
  resolve: {
    'params': function () { return id }
  }
});

我看到了一些建议使用的解决方案:

I saw some suggested solutions to use:

modalInstance.result.then(function(result) {
});

问题是在实际关闭模态窗口之前调用函数回调(当模态窗口仍然是打开的)这不是我想要的行为,因为它意味着它捕获了关闭事件而不是模态的关闭事件。

The problem is that the function callback is called prior to the actual closing of the modal window (when the modal window is still open) and this is not the behavior I want cause it means that it catches the "closing" event and not the "closed" event of the modal.

有没有一种简洁明了的方法来实现它?如果没有,我会感到惊讶,因为这种行为在地球上的任何UI框架中都很常见......

Is there a neat and simple way to implement this? I'd be surprised if not since this behavior is very common in any UI frameworks on the planet...

请帮助!

推荐答案

试试这个。

.open 方法返回一个可以与 .closed 链接的承诺,这是 .open 方法的众多属性之一。

.open method returns a promise that could be chained with .closed which is one of the many properties of .open method.

我对它进行了测试,它仅在模态关闭后显示警报,而不是在关闭时显示警告。

I tested it and it shows the alert only after the modal has closed and not while it's 'closing'.

请参阅返回部分下的已关闭此处

Refer the 'closed' under Return section here

var modalInstance = $uibModal.open({
    templateUrl: "myModalContent.html",
    controller: "termModalCtrl",
    windowClass: 'app-modal-window',
    resolve: {
        'params': function () { return id }
    }
}).closed.then(function(){
  window.alert('Modal closed');
});

这里是plunker http://plnkr.co/edit/yB3k8e3R3ZLQFQ6sfLYW?p=preview

here is the plunker http://plnkr.co/edit/yB3k8e3R3ZLQFQ6sfLYW?p=preview

这篇关于模态关闭后捕获Angular Bootstrap UI $ uibModal关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆