【问题标题】:failing to display bootstrap UI Modal无法显示引导 UI 模式
【发布时间】:2018-01-19 21:03:34
【问题描述】:

在我的 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时,modal没有打开?下面提供了 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>

【问题讨论】:

  • 浏览器控制台说什么?
  • 它没有。没有返回错误。即使调用了函数,我也可以很好地记录一条消息,但 $uibModal 不会运行
  • 不确定;但可能是 CSS 问题?您是否通过检查 chrome 中的 DOM 来检查它是否生成 Modal ?
  • 我看到你正在使用 bootstrap 4 css;您可以尝试使用 bootstrap 3 css 吗?不过不确定!
  • @RahulNaik 您对 Bootstrap 3 的看法是正确的。我需要更新使用的类。写下您的评论作为答案,我会很乐意接受它

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


【解决方案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">

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

【讨论】:

  • 感谢您的宝贵时间
  • np 兄弟...快乐的编码
猜你喜欢
  • 2016-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-20
  • 2015-02-07
  • 2021-07-15
相关资源
最近更新 更多