从覆盖关闭时,角度ui引导模式调用关闭函数

Angular ui bootstrap modal call close function when closing from overlay

本文关键字:模式 调用 函数 角度 覆盖 ui      更新时间:2023-09-26

当用户从覆盖中关闭模态时,我如何运行相同的函数?

例如,现在我有一个带有此功能的关闭按钮:

  close() {
    this.$modalInstance.close();
    this.AlertService.reset();   
  }

但是,当用户从覆盖中关闭模态时,该函数不会运行。

看一下angular bootstrap文档。

$modal.open返回一个模态实例,其中一个参数为"result"。这是一个在模态被驳回时触发的承诺。

var $modalInstance =  $modal.open({ ... });
$modalInstance.result.then(function (selectedItem) {
    $scope.selected = selectedItem;
}, function () {
    $log.info('Modal dismissed at: ' + new Date());
});

此外,请注意关闭前广播的模式关闭事件,该事件可用于防止使用"event.prventDefault"关闭。