0

/public/javascripts我在我的节点项目的目录中有以下角度代码:

var app = angular.module('userContent', ['angularUtils.directives.dirPagination']);

app.controller('MainCtrl', [
'$scope',
  function($scope){
    $scope.users = []

    $scope.addUser = function(){

      if(!$scope.user || $scope.user === '') { return; }
      $scope.users.push({
        user: $scope.user,
        vertrag: $scope.vertrag,
      });

    $scope.user = '';
    $scope.vertrag = '';
    };
  }
]);

这是我的 html 模板,/views位于我的节点项目的目录中

<html>

  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.10/angular-ui-router.js"></script>
    <script src="/javascripts/app.js"></script>
  </head>

  <body ng-app="userContent" ng-controller="MainCtrl">

    <input ng-model="search">

    <table border="1">

      <th>user</th>
      <th>vertrag</th>

      <tr dir-paginate="u in users | filter:search | itemsPerPage: 4">
        <td>{{ u.user }}</td>
        <td>{{ u.vertrag }}</td>
      </tr>

    </table>

    <dir-pagination-controls></dir-pagination-controls>

    <form ng-submit="addUser()">

      <input type="text"
      placeholder="Benutzer"
      ng-model="user">
      </input> <br>

      <input type="text"
      placeholder="Vertrag"
      ng-model="vertrag">
      </input> <br>

      <button type="submit">Submit</button>

    </form>

  </body>

</html>

我用凉亭安装了以下插件,我想使用它。但我总是得到这个错误:

Error: [$injector:modulerr]

我的文件的路径:

/home/ubuntu/project/views/index.ejs
/home/ubuntu/project/public/javascripts/app.js
/home/ubuntu/project/bower_components/angular-utils-pagination
/home/ubuntu/project/bower_components/angular-utils-pagination/dirPagination.js
/home/ubuntu/project/bower_components/angular-utils-pagination/dirPagination.tpl.html
/home/ubuntu/project/bower_components/angular-utils-pagination/bower.json
4

3 回答 3

3

使用 bower 安装并不意味着您准备好了,它只是下载内容。

当 Angular 应用程序找不到给定的模块时,您会收到该错误,在您的情况下angularUtils.directives.dirPagination

您必须在 html之前添加定义angularUtils.directives.dirPagination模块的js。app.js

于 2015-03-11T11:54:47.863 回答
1

如果您的页面中不包含文件,您将收到此错误。您忘记在 html 中包含 dirPagination 文件,因此它在应用程序中不可用并给出模块错误。

于 2015-03-11T11:55:18.497 回答
0

Cem Özer 关于下一步是正确的(但未详细说明),但是在使用 bower install [name] 时,请确保将 --save 添加到末尾,否则将不会保存更改。如果您在没有它的情况下构建,很可能会丢弃该包。

例子:

bower install angular-utils-pagination --save --save 据我所知也适用于 npm

完成此操作后,您希望将 js 文件和 tpl 文件添加到 app.js 文件中(如果遵循最佳实践)。参考这些文件后,您可以添加angularUtils.directives.dirPagination

例子:

angular.module('myApp', ['angularUtils.directives.dirPagination']);

有关如何使用此出色工具的下一步操作的信息,请查看此处的 GITHUB 存储库。

如果您对此有其他疑问,请随时发表评论,我会为您的回答添加更多细节。

于 2016-08-23T20:41:43.757 回答