javascript - 无法显示 bootstrap UI 模态

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

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

我已经注入(inject)了所有正确的依赖项,加载了所有正确的 CDN,并且功能正在运行,但我的 Controller 似乎无法访问 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 所需的模块注入(inject)如下:

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

我的 Controller 位于 Angular 组件 内,也具有所需的注入(inject),如下所示:

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>

最佳答案

除了 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">

因为您使用的是 Angular ui bootstrap uibModal 并且它的模板确实包含 bootstrap 3 类,并且包含 bootstrap 3 css 模式弹出窗口应该可以工作。

关于javascript - 无法显示 bootstrap UI 模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45633609/

相关文章:

javascript - 尝试使用JS在Bootstrap中制作虚拟键盘

javascript - 无法使用 firebase.firestore.FieldValue.increment

javascript - 如何使用 jQuery 一起显示选定的值?

javascript - 我如何重新排序 bootstrap 3 div?

php - 有什么方法可以使 MySql 数据库成为 "update itself"吗?

javascript - ng-model 在模态中没有绑定(bind)两种方式

javascript - Bootstrap 3 : prevent modal inside modal to trigger (hidden. bs.modal) 每次

javascript - AngularJS 动态路由

javascript - 当值在 AngularJS 之外更改时,AngularJS 指令范围不更新

html - 使用 Bootstrap 布局页脚网格