从 angular $uibModal 背景点击返回数据

Returning data from angular $uibModal backdrop click

我正在尝试从 uibModal 传回一个值。如果用户单击模式的关闭按钮

,我可以定义 return
$scope.close = function () {
    $modalInstance.close($scope.editMade);
};

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

如何为该特定事件定义 return 值?

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

尝试在模态中使用这个:

$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
 });

检查这个正在运行的插件。它使用我提到的解雇

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

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

模态控制器中的代码:

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

然后在你的父控制器中:

 $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

在模态控制器中,你可以这样做:

$scope.$on('modal.closing', function(event, reason, closed) {
                if (reason == "backdrop click" || reason == "escape key press")
                {
                    event.preventDefault();
                    $uibModalInstance.close({"data": somedata});
                }                
            });

这样您将始终在 modalInstance 上获得成功回调

modalInstance.result.then(function(response) {
// here response will be whatever is passed. in this sample {"data": somedata}
});