我一直盯着这段代码看了45分钟,感到很困惑。我扔了很多游戏机。在代码中,看起来一切都按照我写的方式工作,但它在浏览器中不起作用。
基本上,我使用ng-idle在会话到期后将用户签出。当他们登出时,出现一个模态显示"您因不活动而登出"。美元的模态。Open for this被包装在一个条件语句中
这个模式在用户第一次登出时出现,但是在下一次登出后它没有出现,即使如果您查看console.log的,它实际上在if语句中包含$modal.open。下面是html(也许它很有用,但你永远不会知道)和代码:
<div class="modal-dialog session-timeout">
<h3 style="text-align: center;">You have been logged out due to inactivity.</h3>
<button type="button" class="btn btn-primary" style="margin: auto;">OK</button>
</div>
angular.module('app').run(function($rootScope, $state, $modal, Api, User, Cache) {
$rootScope.$on('IdleTimeout', function() {
console.log('DING!!!!!!')
var timedOut = false;
console.log('line 98', timedOut);
return Api.get('/users/logout').then(function (response) {
console.log('INSIDE RETURN');
Api.setupHeader('');
_.each(Object.keys(localStorage), function (key, value) {
Cache.removeItem(key);
User.currentUser = null;
$rootScope.$broadcast('sign-out');
});
console.log('line 107', timedOut);
timedOut = true;
console.log('line 109 ', timedOut);
if(timedOut === true) {
console.log('INSIDE IF');
$modal.open({
templateUrl: 'logged-out.html',
windowClass: 'session-timeout'
});
}
$rootScope.isLogin = false;
$state.go('home.home-index');
timedOut = false;
});
});
});
我不熟悉Angular,但我知道如果你试图打开一个引导模态,如果包含的div不知怎么消失了,它将无法工作。您确定您的视图没有重新渲染,因此您认为存在的div没有?