ZedsWhatSheSaid ZedsWhatSheSaid - 3 months ago 16
AngularJS Question

AngularJS Error: [$injector:modulerr]

I have following angular code which is in my

/public/javascripts
dir in my node project:

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 = '';
};
}
]);


This is my html template which is in my
/views
dir in my node project

<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>


I installed following plugin with bower, which I want to use. But I always get this error:

Error: [$injector:modulerr]


Path to my files:

/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

Answer

Installing with bower does not mean you are ready to go, it just downloads contents.

You get that error when Angular app cannot find given module, in you case angularUtils.directives.dirPagination.

You have to add js that defines angularUtils.directives.dirPagination module before your app.js in your html.

Comments