這裏我有一個引導彈出窗口。它工作正常。當我們點擊確定按鈕時它會關閉彈出窗口。但我想關閉特殊情況下的彈出窗口。如何關閉我們想要的彈出窗口
當滿足以下條件時我想關閉已經打開的彈出窗口。
if(x==y){
$uibModalInstance.close();
}
但它沒有關閉彈出窗口。我在控制檯上收到以下錯誤。
ReferenceError: $uibModalInstance is not defined
JSP: -
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title" id="modal-title">{{ctrl.modalHeader}}</h3>
</div>
<div class="modal-body" id="modal-body">
{{ctrl.modalBody}}
<ul ng-repeat="item in ctrl.list">
<li ng-repeat="(key,value) in item">{{value}}</li>
</ul>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="ctrl.ok()">OK</button>
<!--<button class="btn btn-warning" type="button" ng-click="ctrl.cancel()"><spring:message code="label.close"/></button>-->
</div>
</script>
JSP依賴是: -
<script src="js/commons/ui-bootstrap-tpls-2.4.0.js"></script>
角控制器: -
var app = angular.module('App', ['ui.bootstrap']);
app.controller('facilitoController', function($scope, $window, $filter, $uibModal) {
if(x==y){
//Here I am failing to close the popup
$uibModalInstance.close();
}
$scope.open = function() {
var modalInstance = $uibModal.open({
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'myModalContent.html',
controller: function($uibModalInstance) {
var self = this;
self.modalHeader = modalHeader;
self.modalBody = modalBody;
self.list = exceptions;
self.ok = function() {
$uibModalInstance.close();
};
self.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
},
controllerAs: 'ctrl'
});
}
};
進樣$:
看看工作的例子,如果在彈出被打開之前,將關閉在控制器初始化後5秒彈出uibModalInstance在你的控制器的依賴(第三行) – Antikhippe