我创建了一个如下所示的路线配置:
angular.module('kappa.configs',['ngRoute'])
.config(['$routeProvider',function($routeProvider){
$routeProvider.when('/',{
controller: 'MainCtrl',
resolve: {
getPlate: ['$http',function($http){
return $http.get('samples.json');
}]
}
});
}]);
angular.module('kappa.controllers',[])
.controller('MainCtrl',['$scope','$http','SamplesService','getPlate',function($scope,$http,SamplesService,getPlate){
$scope.fullPlate = getPlate;
// Some more code here
}]);
//Some more code
angular.module('kappa',['ngResource','ngRoute','kappa.services','kappa.controllers','kappa.configs']);
但是我得到了一个未知的提供程序错误,如下所示:
Error: [$injector:unpr] Unknown provider: getPlateProvider <- getPlate
http://errors.angularjs.org/1.2.9/$injector/unpr?p0=getPlateProvider%20%3C-%20getPlate
at http://code.angularjs.org/1.2.9/angular.js:78:12
at http://code.angularjs.org/1.2.9/angular.js:3546:19
at Object.getService [as get] (http://code.angularjs.org/1.2.9/angular.js:3673:39)
at http://code.angularjs.org/1.2.9/angular.js:3551:45
at getService (http://code.angularjs.org/1.2.9/angular.js:3673:39)
at invoke (http://code.angularjs.org/1.2.9/angular.js:3700:13)
at Object.instantiate (http://code.angularjs.org/1.2.9/angular.js:3721:23)
at http://code.angularjs.org/1.2.9/angular.js:6772:28
at http://code.angularjs.org/1.2.9/angular.js:6185:34
at forEach (http://code.angularjs.org/1.2.9/angular.js:310:20)
我被困在这里..感谢任何帮助..
答案 0 :(得分:3)
如果您尝试在route
的上下文之外的任何位置使用控制器,则会遇到此问题。如果你的模板中某处有ng-controller="MainCtrl"
,或者你正在使用另一条没有getPlate
解析器的路线。
工作演示:http://plnkr.co/edit/J4thldg3aWmC9e8UAHut?p=preview
如果您在模板中的任何位置加入ng-controller="MainCtrl"
,则会看到错误。