就在第一个用户登录我的应用程序后,我弹出一个条款和条件。它可以在开发工具中轻松关闭,并且可以免费使用该应用程序。如何查看sessionStorage变量requireTerms
?根据条款是否被接受,requireTerms从true变为false。
如果要在HTML编辑器中关闭模式并重新打开弹出窗口,我想检测一下点击。
是否有AngularJS方式来设置配置来做到这一点?
我的一项服务中就有此功能
var service = this;
service.showTerms = function() {
$uibModal.open({
templateUrl: 'app/terms/terms.html',
controller: 'tsAndCs as vm',
size: 'md',
backdrop: false,
keyboard: false
}).result.then(function(response) {
}, function() {
});
};
所以我基本上可以调用appState.showTerms();
,但是我试图弄清楚如何检测到该窗口被迫关闭并调用该函数。
@edit
我想到了在显示模式时编写一个变量requireTermsOpened
(仅当用户实际单击'Accept'时该变量才会设置为false)并写类似
var requireTerms = sessionStorage.getItem('requireTerms');
var requireTermsOpened = sessionStorage.getItem('requireTermsOpened');
if(requireTerms && requireTermsOpened) {
appState.showTerms();
}
答案 0 :(得分:0)
$uibModal.open({
templateUrl: 'app/terms/terms.html',
controller: 'tsAndCs as vm',
size: 'md',
backdrop: false,
keyboard: false
}).result.then(function(response) {
})
.catch(function() {
// Here you can add your code, its the event that gets called when the modal is dimissed
});
请对其进行测试,我很确定它会为您提供帮助,如果格式不好,很抱歉,我相信您已经明白了,对吧?
答案 1 :(得分:0)
您可以尝试以下代码。另外,请针对您给定的示例场景检查此plunker。
控制器:
$scope.modelFn = function() {
var modalInstance = $uibModal.open({
templateUrl: 'confirmationWindow.html',
windowClass: 'modal',
controller: function ($scope, $uibModalInstance) {
$scope.confirm = function(userAgreement) {
$uibModalInstance.close(userAgreement);
};
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
},
size: 'md',
backdrop: false,
keyboard: false
});
modalInstance.result.then(function(selectedItem) {
if (selectedItem) {
alert('Selected check box and clicked OK!');
}else{
alert('Clicked OK Button without Selecting Checkbox!');
}
}, function() {
alert('Clicked Cancel button or Considered cancel on click of outside the Model popup window!');
});
};
模板:
<div ng-controller="MainCtrl">
<script type="text/ng-template" id="confirmationWindow.html">
<div class="modal-header">
<h3 class="modal-title">Terms & Conditions</h3>
</div>
<div class="modal-body">
<p>...........</p>
<p>
<input type="checkbox" ng-model="userAgreement"/>
Are you agreed with all terms and conditions?</p>
</div>
<div class="modal-footer">
<button class="btn btn-warning" ng-click="confirm(userAgreement)">Confirm</button>
<button class="btn btn-default" ng-click="cancel()">Cancel</button>
</div>
</script>
<button class="btn" ng-click="modelFn()">Open Modal</button>
</div>