【问题标题】:Reject dismiss event with $modalInstance in angularjs在 angularjs 中使用 $modalInstance 拒绝关闭事件
【发布时间】:2015-10-10 06:42:41
【问题描述】:

我在 Angular js 应用程序中使用引导模式,如果条件为真,我想推迟关闭模式窗口。我似乎无法让这个工作。我的 $scope.close() 函数有一个函数,但这是关于单击引导背景时默认的 dismiss() 行为。

$modalInstance.result.catch ((event)->
    if event == 'backdrop click'
        console.log 'check condition and cancel dismiss'
    return
), (event) ->
    return

【问题讨论】:

  • 您的意思是要阻止用户根据某些条件关闭模态框吗?如果这是您想要的,那么这是放置该代码的错误位置。
  • 你为什么不检查调用dismiss的函数?
  • 是的,如果存在条件我想取消模态解除功能。
  • 这是在单击模态背景时覆盖默认行为,它只调用了dismiss(),而不是来自函数调用

标签: angularjs bootstrap-modal angular-bootstrap


【解决方案1】:

有一个“背景”选项,可以设置为真(默认)、假或“静态”(存在但不关闭模式)。 您可以将范围变量作为该选项的值:

$scope.backdropOption = true; //or false or 'static'
$scope.open = function (size) {

  var modalInstance = $uibModal.open({
    templateUrl: 'myModalContent.html',
    controller: 'ModalInstanceCtrl',
    backdrop: $scope.backdropOption,
  });

  modalInstance.result.then(function () {
    ...
  }, function () {
    ...
  });
};

【讨论】:

  • 谢谢,我想让背景保持启用状态,因为如果某个变量为真,我只想拒绝它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-21
  • 1970-01-01
  • 1970-01-01
  • 2015-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多