为什么我的引导模式包含在条件中第一次打开,但第二次不打开?

时间:2016-08-17 21:34:31

标签: angularjs bootstrap-modal

我在过去的45分钟里一直盯着这段代码而且感到难过。我在代码中抛出了大量的console.logs,看起来一切都按照我编写的方式工作,但它不能在浏览器中工作。

基本上我在会话到期后使用ng-idle对用户进行签名。当他们退出时,会出现一个模式,显示“由于不活动而您已退出”。 $ modal.open用于包含在条件。

这个模式在用户第一次注销时出现,但是下次没有出现之后,即使你查看console.log,它实际上也在包含$ modal.open的if语句中。这是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;
    });
  });
});

1 个答案:

答案 0 :(得分:0)

我不熟悉Angular,但我知道如果你试图打开一个bootstrap模式,如果包含的div已经以某种方式消失了它将无法工作。你确定你的视图没有重新渲染,因此你认为不存在你的视图吗?