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

How to pass model value on close modal popup?(Angularjs)

我在 angularjs 中有一个 bootstrap 模态弹出窗口。 我的 plunker 在这里:Links

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

代码:

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

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

    });

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

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

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

请注意,随事件传递的 data 将是 "cancel"、"backdrop click" 或所选项目(当他们单击“确定”时)。

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

this revised plunker 中查看。