如何在AngularUIBootstrap中查看模态是否打开

How to see whether modal is open in Angular UI Bootstrap

我正在使用 Angular UI Bootstrap。如果模式打开,我想显示 true。如果没有打开,我想显示false。有没有办法在 HTML?

中做到这一点

我尝试使用下面的代码,但它是错误的:

<code>myForm.$modalStack.opened={{myForm.$modalStack.opened}}</code>

对如何正确执行此操作有任何想法吗?

下面是我用来触发模态的相关代码:

HTML:

<button ng-click="myForm.agreement()">

控制器中的代码:

.controller('MyFormCtrl',
  function ($location, $stateParams, $modal, $scope, $http) {
    var myForm = this;
    // . . . 

   myForm.agreement = agreement;

   function agreement() {

       $modal.open({

          templateUrl: 'views/agreement.html'
  })
});

$modal.open 返回的 opened 属性 是一个你可以挂钩的承诺。

因此,使用他们的示例,请参见此处 - http://plnkr.co/edit/PsEqTIy8CDUU88HMLxbC?p=preview

$scope.modalOpen = false;
$scope.open = function (size) {
    var modalInstance =  $modal.open({
        animation: $scope.animationsEnabled,
        templateUrl: 'myModalContent.html',
        controller: 'ModalInstanceCtrl',
        size: size,
        resolve: {
            items: function () {
                return $scope.items;
            }
        }
    });

    modalInstance.opened.then(function () {
        $scope.modalOpen = true;
    });

    // we want to update state whether the modal closed or was dismissed,
    // so use finally to handle both resolved and rejected promises.
    modalInstance.result.finally(function (selectedItem) {
        $scope.modalOpen = false;
    });
};

您想调用 promises 然后做任何您需要的事情。 .opened 是模式打开时的承诺,.result 是模式关闭时的承诺。所以使用这个想法,你会使用 $scope.modalOpen 作为你的布尔值。