AngularJS错误:[$ injector:modulerr]

时间:2015-03-11 11:47:50

标签: angularjs angularjs-module

我的节点项目中的/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>

我用凉亭安装了following plugin,我想使用它。但我总是得到这个错误:

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

3 个答案:

答案 0 :(得分:3)

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

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

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

答案 1 :(得分:1)

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

答案 2 :(得分: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存储库here

如果您对此有任何疑问,请随时发表评论,我会为您的答案添加更多详细信息。