javascript - IdleProvider.windowInterrupt 不是函数

标签 javascript angularjs node.js gruntjs yeoman

我正在尝试在我的 devbox 上的 node.js 中获得 ng-Idle 最基本的可能实现。为此,我采取了the minimal sample shown at this link ,并将其安装在 node.js 的工作最小安装中,我使用 instructions which I have documented at a file sharing site at this link 实现了它。 。我对工作最小 Node.js 应用程序所做的就是进入一个工作极简应用程序,

1.) Tyoe bower install ng-idle 在客户端应用程序的根文件夹中
2.) 注释掉所有旧的 index.html
3.) 将上面链接中的以下代码粘贴到 index.html 中,仅将 url 链接更改为 angular.jsangular-idle.min。 js 到项目中这些文件的实际相对路径。 (我确认这两个链接都指向实际的 js 库。
4.) 在应用程序所在的客户端文件夹的根目录中键入 gruntserve

上述步骤在网络浏览器中启动了应用程序,但出现以下编译错误:

Error: [$injector:modulerr] Failed to instantiate module demo due to:
IdleProvider.windowInterrupt is not a function
@http://localhost:9000/:122:9  

如果有人对重现这个简单问题的完整工作应用程序感兴趣,我将其放在 a tar ball and posted it to a file sharing site, which you can download by clicking on this link 中。 。

需要采取哪些具体步骤来解决此错误,以便 ng-idle 可以在 Node.js 的基本安装中运行?

这是index.html:

<html ng-app="demo">
  <head>
    <title title>NgIdle Sample</title>
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/ng-idle/angular-idle.min.js"></script>

   <script type="text/javascript">
      var app = angular.module('demo', ['ngIdle']);
      app
      .controller('EventsCtrl', function($scope, Idle) {
        $scope.events = [];
        $scope.idle = 5;
        $scope.timeout = 5;
        $scope.$on('IdleStart', function() {
          addEvent({event: 'IdleStart', date: new Date()});
        });
        $scope.$on('IdleEnd', function() {
          addEvent({event: 'IdleEnd', date: new Date()});
        });
        $scope.$on('IdleWarn', function(e, countdown) {
          addEvent({event: 'IdleWarn', date: new Date(), countdown: countdown});
        });
        $scope.$on('IdleTimeout', function() {
          addEvent({event: 'IdleTimeout', date: new Date()});
        });
        $scope.$on('Keepalive', function() {
          addEvent({event: 'Keepalive', date: new Date()});
        });
        function addEvent(evt) {
          $scope.$evalAsync(function() {
            $scope.events.push(evt);
          })
        }
        $scope.reset = function() {
          Idle.watch();
        }
        $scope.$watch('idle', function(value) {
          if (value !== null) Idle.setIdle(value);
        });
        $scope.$watch('timeout', function(value) {
          if (value !== null) Idle.setTimeout(value);
        });
      })
      .config(function(IdleProvider, KeepaliveProvider) {
        KeepaliveProvider.interval(10);
        IdleProvider.windowInterrupt('focus');
      })
      .run(function($rootScope, Idle, $log, Keepalive){
        Idle.watch();
        $log.debug('app started.');
      });
    </script>
  </head>
  <body ng-controller="EventsCtrl">
    <div idle-countdown="countdown">
      <h1>Idle and Keepalive events</h1>
      <button type="button" ng-click="reset()">Reset manually</button>
      <ul>
        <li ng-repeat="event in events">{{event}}</li>
      </ul>

      <div idle-countdown="countdown">
        Timeout in {{countdown}} seconds.
      </div>

      <div>
        Change idle value <input type="number" ng-model="idle" />
      </div>
      <div>
        Change timeout value <input type="number" ng-model="timeout" />
      </div>
    </div>
  </body>
</html>

最佳答案

对此感到抱歉。该存储库使用 git-flow 源代码控制技术,因此 develop 分支是未发布的工作所在,而 master 代表发布分支。您正在查看的 index.html 包含一个示例,说明如何使用已添加但尚未正式发布的功能。

我将继续发布待处理的功能,但与此同时,您可以删除 IdleProvider.windowInterrupt 行,因为它在版本 1.1.1 中不可用。该版本中的示例index.html 可在master 中找到。 .

我运行了您的示例,删除了该行,它按预期工作。

关于javascript - IdleProvider.windowInterrupt 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35445127/

相关文章:

javascript - 如何使用 Angular 或 JQuery 删除来自本地存储的前导和尾随双引号

css - 通过单击上一组中的按钮更改 UI Bootstrap Accordion 组内容

java - 使用 Java 和 Vue 创建 Web 应用程序的更好方法

javascript - 类列表切换不会为 div 添加/切换类名

javascript - 下载一个文件,片段存储在多个服务器上(HTTP)

javascript - 在动态变量上调用js函数

node.js - 我的node.js流代码有什么问题?

javascript - 当侧边菜单 div 接近 0px 时导航链接不隐藏

angularjs - 是否可以使用范围变量 angularjs 解析字符串?

javascript - 如何使用 docs-api (node) 将 N 个 google 文档合并为一个