从 angular $uibModal 背景返回数据单击 [英] Returning data from angular $uibModal backdrop click

查看:25
本文介绍了从 angular $uibModal 背景返回数据单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 uibModal 传回一个值.如果用户单击模态的关闭按钮,我可以定义返回

I'm trying to pass back a value from a uibModal. I can define the return if the user clicks the modal's close button

$scope.close = function () {
    $modalInstance.close($scope.editMade);
};

但是如果用户单击背景区域,这将不起作用.

But this doesn't work if the user click the backdrop area.

如何为特定事件定义返回值?

How can I define a return value for that particular event?

推荐答案

当你点击外面的背景时,它会在内部关闭.

When you click on the backdrop outside, it does a dismiss internally.

尝试在模态中使用它:

$modalInstance.dismiss($scope.editMade);

并使用它来处理数据:

 instance.result.then(function(){
  //Get triggers when modal is closed
 }, function(){
  //gets triggers when modal is dismissed. You can basically handle data here
 });

检查这个工作的plunker.它使用我提到的解雇

Check this working plunker. It uses the dismiss as I mentioned

http://embed.plnkr.co/YdWmqYPFBNbv4vhQZc4t/

关闭模态时将自定义数据传递给父控制器:

模态控制器中的代码:

  $scope.$on("modal.closing",function(){
       $rootScope.$broadcast("modalClosing",$scope.editMade);
  });

然后在您的父控制器中:

Then in your parent controller:

 $scope.$on("modalClosing",function(event,value){
    console.log(value); //value should be $scope.editMade
  });

您可以通过阅读此处的文档了解更多信息:https://github.com/angular-ui/bootstrap/tree/master/src/modal/docs

You can learn more by reading the documentation here: https://github.com/angular-ui/bootstrap/tree/master/src/modal/docs

这篇关于从 angular $uibModal 背景返回数据单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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