Angular JS:错误:[$ injector:unpr]

时间:2016-02-29 20:06:29

标签: javascript angularjs

请不要标记为重复我访问过一些与此相关的问题,一切看起来都不错,但仍然收到此错误。请帮忙。我是angularjs的新手

的index.html

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
    <meta charset="UTF-8">
    <title>Angular JS</title>
    <script src="lib/angular.min.js"></script>
    <script src="lib/angular-route.min.js"></script>

    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
    <div class="main" ng-view></div>
</body>
</html>

list.html

<ul class="artistlist">
    <li class="artist cf" ng-repeat="item in artists | filter:artistFilter | orderBy:artistOrder:direction">
        <img ng-src="images/{{item.shortname}}_tn.jpg" alt="{{item.name}}">
        <div class="info">
            <h2>{{item.name|uppercase}}</h2>
            <h3>{{item.reknown}}</h3>
        </div>
    </li>
</ul>

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

controllers.js

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

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

完整错误

Error: [$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://localhost/angular/lib/angular.min.js:6:449
    at http://localhost/angular/lib/angular.min.js:32:125
    at Object.c [as get] (http://localhost/angular/lib/angular.min.js:30:200)
    at http://localhost/angular/lib/angular.min.js:32:193
    at c (http://localhost/angular/lib/angular.min.js:30:200)
    at Object.d [as invoke] (http://localhost/angular/lib/angular.min.js:30:417)
    at http://localhost/angular/lib/angular.min.js:32:211
    at c (http://localhost/angular/lib/angular.min.js:30:200)
    at Object.d [as invoke] (http://localhost/angular/lib/angular.min.js:30:417)

1 个答案:

答案 0 :(得分:3)

感谢您提供错误消息。没有它,几乎不可能找到错误。

我认为这可能对您有所帮助: https://stackoverflow.com/a/26230442/3741957

(似乎有角度/ ngRoute的版本不匹配)