我正在使用Angular UI Bootstrap.如果一个模态打开,我想显示true.如果它没有打开,我想显示错误.有没有办法在
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返回的打开属性是一个可以挂钩的承诺.
所以,使用他们的例子,请看这里 – 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; }); };
你想打电话给承诺,然后做你需要的任何事情. .opened是模态打开时的承诺,而.result是模态关闭时的承诺.因此,使用这个想法,您将使用$scope.modalOpen作为您的布尔值.