Angular bootstrap 模态事件

Angular bootstrap modal events

我正在尝试为整个项目中的所有 UI 模态触发事件,我希望在任何 UI 模态打开或关闭时触发事件?

示例:

anymodal.opened.then(function() {});

摘自文档(版本 2.1.4)

The open method returns a modal instance, an object with the following properties:

close(result) (Type: function) - Can be used to close a modal, passing a result.

dismiss(reason) (Type: function) - Can be used to dismiss a modal, passing a reason.

result (Type: promise) - Is resolved when a modal is closed and rejected when a modal is dismissed.

opened (Type: promise) - Is resolved when a modal gets opened after downloading content's template and resolving all variables.

closed (Type: promise) - Is resolved when a modal is closed and the animation completes.

rendered (Type: promise) - Is resolved when a modal is rendered.

你要找的是最后三个

像通常使用模态实例一样使用它们

var modalInstance = $uibModal.open({
    // define you modal here ...
});

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

modalInstance.opened.then(function() {
  console.log("modal opened");
}) 

modalInstance.closed.then(function() {
  console.log("modal closed");
})

modalInstance.rendered.then(function() {
  console.log("modal rendered");
})