点击角度ui bootstrap模式时如何捕捉背景点击事件? [英] How to catch backdrop click event when clicked out of angular ui bootstrap modal?

查看:79
本文介绍了点击角度ui bootstrap模式时如何捕捉背景点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,它使用 $ modal.open()函数打开一个模式弹出窗口,该模式弹出窗口使用另一个页面作为模板。单击按钮时,它显示模态弹出窗口正常。如果我单击取消按钮然后它正在调用此函数并且也正常工作。

In my application, it is using $modal.open() function to open a modal popup which is using another page as a template. While clicking the button, it is showing the modal popup fine. If I click the Cancel button then it is calling this function and working fine also.

    $scope.cancel=function(){
    });

但如果用户点击模态弹出窗口外,我们无法通过此代码捕获该事件

But if the user clicks outside the modal popup, we are unable to catch that event by this code

    $scope.dismiss=function(){
    });

如何捕获该事件?

我见过AngularJS的很多文章,但找不到解决方法。

I have seen many articles of AngularJS, but couldn't find a solution for this.

推荐答案

$ modal.open()返回一个带有promise的对象。您可以使用promise并链接它,并在catch中处理它。当您点击外面的背景时,它会在内部执行解除并拒绝承诺。

$modal.open() returns a object with a promise. You can use the promise and chain it though, and handle it in the catch. When you click on the backdrop outside, it does a dismiss internally and it rejects the promise.

ex: -

var instance = $modal.open(...);

 instance.result.then(function(){
  //Get triggers when modal is closed
 }, function(){
  //gets triggers when modal is dismissed.
 });

如果你在孩子身上使用这个 $ modalInstance 你也可以在那里做到。所以基本上而不是处理事件这有助于你在承诺的帮助下在更高的层次上做。

If you are using this in the child where $modalInstance is injected you could do that there as well. So basically rather than dealing with event this helps you do it at a higher level with the help of promises.

这篇关于点击角度ui bootstrap模式时如何捕捉背景点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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