从角度$ uibModal背景幕返回数据 [英] Returning data from angular $uibModal backdrop click

查看:198
本文介绍了从角度$ 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
 });

检查此工作的插塞器.它使用了我所说的解雇方式

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

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

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