无法显示引导UI模式

时间:2017-08-11 11:01:53

标签: javascript angularjs twitter-bootstrap angular-ui-bootstrap ng-idle

在我的AngularJS应用程序中,我正在使用ngIdle模块,并按照作者在他的Github上分享的演示https://hackedbychinese.github.io/ng-idle/

我注入了所有正确的依赖项,加载了所有正确的CDN,并且函数正在运行,但似乎我的控制器无法访问bootstrap-ui $uibModal

我的CDN和文件按如下方式加载:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ng-idle/1.3.2/angular-idle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap-tpls.min.js"></script>

ui-bootstrapngIdel的必需模块都是这样注入的:

var app = angular.module('myApp', ['ngIdle', 'ui.bootstrap']);

我的控制器,在Angular component内,也有所需的注射:

app.component('patents', {
    bindings: { patents: '<' },
    templateUrl: 'p3sweb/app/components/patents/views/list-patents.htm',
    controller: function($state, $scope, Idle, Keepalive, $uibModal) {

    $scope.started = false;

        function closeModals() {
        if ($scope.warning) {
          $scope.warning.close();
          $scope.warning = null;
        }

        if ($scope.timedout) {
          $scope.timedout.close();
          $scope.timedout = null;
        }
        }

      $scope.$on('IdleStart', function() {
        closeModals();
        $scope.warning = $uibModal.open({
          templateUrl: 'warning-dialog.html',
          windowClass: 'modal-danger'
        });
      });

      $scope.$on('IdleEnd', function() {
        closeModals();
      });
});

问题

为什么当函数正在运行且没有返回错误时,当用户是Idel时模式是否打开?下面提供了HTML。

<section>
  <p>
    <button type="button" class="btn btn-success" ng-hide="started" ng-click="start()">Start Demo</button>
    <button type="button" class="btn btn-danger" ng-show="started" ng-click="stop()">Stop Demo</button>
  </p>
</section>

<script type="text/ng-template" id="warning-dialog.html">
  <div class="modal-header">
   <h3>You're Idle. Do Something!</h3>
  </div>
  <div idle-countdown="countdown" ng-init="countdown=5" class="modal-body">
   <uib-progressbar max="5" value="5" animate="false" class="progress-striped active">You'll be logged out in {{countdown}} second(s).</uib-progressbar>
  </div>

</script>
<script type="text/ng-template" id="timedout-dialog.html">
  <div class="modal-header">
   <h3>You've Timed Out!</h3>
  </div>
  <div class="modal-body">
   <p>
      You were idle too long. Normally you'd be logged out, but in this demo just do anything and you'll be reset.
   </p>
 </div>
</script>

1 个答案:

答案 0 :(得分:1)

除了bootstrap css,你在这里做得很好。 我相信你需要包含bootstrap 3 CSS

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

因为你正在使用角度ui bootstrap uibModal,它的模板包含bootstrap 3类,包括bootstrap 3 css模式弹出窗口应该可以工作。