我正在使用 Angular UI Bootstrap。如果模态打开,我想显示 true
。如果它没有打开,我想显示 false
。有没有办法在 HTML 中做到这一点?
我尝试使用以下代码,但它是错误的:
<code>myForm.$modalStack.opened={{myForm.$modalStack.opened}}</code>
关于如何正确执行此操作的任何想法?
在我用来触发模态的相关代码下方:
HTML:
<button ng-click="myForm.agreement()">
Controller 中的代码:
.controller('MyFormCtrl',
function ($location, $stateParams, $modal, $scope, $http) {
var myForm = this;
// . . .
myForm.agreement = agreement;
function agreement() {
$modal.open({
templateUrl: 'views/agreement.html'
})
});
最佳答案
opened
返回的 $modal.open
属性是一个可以 Hook 的 promise 。
因此,使用他们的示例,请参见此处 - 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;
});
};
你想调用 promise ,然后做任何你需要的事情。
.opened
是模式打开时的 promise ,.result
是模式关闭时的 promise 。所以使用这个想法,你可以使用 $scope.modalOpen
作为你的 bool 值。
关于angularjs - 如何在 Angular UI Bootstrap 中查看模态是否打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31594640/