如何在关闭模态弹出窗口上传递模型值?(Angularjs)

时间:2015-06-06 05:27:43

标签: angularjs angular-ui-bootstrap

我在angularjs中有一个bootstrap模式弹出窗口。 我的傻瓜在这里:Links

我的问题是,我希望不仅在关闭按钮上的关闭弹出窗口中获得选定的值。如果用户想要从像黑色背景的区域外关闭也需要获得选定的值。

代码:

modalInstance.result.then(function (selectedItem) {
      $scope.selected = selectedItem;
    }, function () {

     // Here i want to get selected item like as above

    });

1 个答案:

答案 0 :(得分:3)

modal directive的文档中,最后一段提到了当模态关闭时在模态对话框控制器范围内调度的modal.closing事件。

您可以使用此事件来确定模式的关闭方式:

$scope.$on('modal.closing', function(event, data) {
  console.log(data);
  if (data == 'backdrop click') {
    event.preventDefault();
    $scope.ok();
};

请注意,随此事件传递的data将为“取消”,“背景点击”或所选项目(当他们点击“确定”时)。

在单击背景的特定情况下,可以阻止模式关闭,然后调用“OK”代码路径。

this revised plunker中查看。

相关问题