Search code examples
javascriptangularjsangularjs-injector

AngularJS: Error: $injector:unpr in simple script


I did this tutorial that has the code running and I tried to make it into my own. But unfortunately, it doesn't work. It gives eh following error:

angular.min.js:84Error: [$injector:unpr] http://errors.angularjs.org/1.2.9/$injector/unpr?p0=%24templateRequestProvider%20%3C-%20%24templateRequest%20%3C-%20%24route%20%3C-%20ngViewDirective
at Error (native)
at http://portfolio2.gerbenboersma.com/lib/angular.min.js:6:449
at http://portfolio2.gerbenboersma.com/lib/angular.min.js:32:125
at Object.c [as get] (http://portfolio2.gerbenboersma.com/lib/angular.min.js:30:200)
at http://portfolio2.gerbenboersma.com/lib/angular.min.js:32:193
at c (http://portfolio2.gerbenboersma.com/lib/angular.min.js:30:200)
at Object.d [as invoke] (http://portfolio2.gerbenboersma.com/lib/angular.min.js:30:417)
at http://portfolio2.gerbenboersma.com/lib/angular.min.js:32:211
at c (http://portfolio2.gerbenboersma.com/lib/angular.min.js:30:200)
at Object.d [as invoke] (http://portfolio2.gerbenboersma.com/lib/angular.min.js:30:417)

I know this error has been posted here more often, but most of them are dealing with more complicated code than mine and it doesn't seem to apply.

The tutorial that I was following is uploaded right here, in working condition: http://gerbenboersma.com/sites/AngularTests/

And my own code is almost similar to it, in my last version I even used all of the same names. Here it is:

<!doctype html>
<html lang="en" ng-app="myApp">
<head>
    <title>Gerben Boersma | Portfolio | 2016</title>
    <link rel="stylesheet" href="css/styles.css">
    <script src="lib/angular.min.js"></script>
    <script src="lib/angular-route.min.js"></script>
    <script src="js/works.json"></script>
    <script src="js/controllers.js"></script>
    <script src="js/app.js"></script>
</head>
<body>
<div class="outer-content">
    <div class="green-bar"></div>
    <div class="content" ng-view>
    </div>
</div>
</body>
</html>

And controllers.js:

var artistControllers = angular.module('artistControllers', []);

artistControllers.controller('ListController', ['$scope', '$http', function($scope, $http) {
  $http.get('js/works.json').success(function(data) {
    $scope.works = data;
    $scope.artistOrder = 'name';
  });
}]);

And app.js:

var myApp = angular.module('myApp', [
  'ngRoute',
  'artistControllers'
]);

myApp.config(['$routeProvider', function($routeProvider) {
  $routeProvider.
  when('/list', {
    templateUrl: 'partials/list.html',
    controller: 'ListController'
  }).
  otherwise({
    redirectTo: '/list'
  });
}]);

I've been looking at these pieces for too long, and it isn't even so much. Yet I am unable to locate the problem. According to the AngularJS Error reference there might be something wrong with the way I named things, but in these latest versions I didn't even change the names from the original tutorial examples, which seems to work pretty well. I hope someone can shed some light on this.


Solution

  • you are using angular 1.2.9 along with new angular-route 1.5.8, this causes mentioned issue, just use angular 1.5.8 instead of 1.2.9, I created plunker: http://plnkr.co/edit/szCGtnZQsXYFkTrjBNZZ?p=preview, try to uncomment 1.2.9 and comment 1.5.8 versions of angular, and issue will be replicated

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js"></script>
    <!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.9/angular.min.js"></script> -->