Before voting, yes, this question has already been asked and answered, but the answers are not satisfactory. They all correctly suggest adding a controller to the route configuration, but this is not the case here.
The expected behavior of the routeProvider object resolve xxxmust be entered into the controller:
var app = angular.module('X', [])
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/',{
controller:'XCtrl',
templateUrl: 'x.html',
resolve: {
xxx: function () {
return 'XXX from routing config.';
}
}
})
}])
.controller('XCtrl', function($scope, xxx) {
console.log('xxx = '+xxx);
});
The console should get a record xxx = XXX from routing config..
Instead, fetching the code above fails:
Error: [$injector:unpr] Unknown provider: xxxProvider <- xxx
http://errors.angularjs.org/1.2.10/$injector/unpr?p0=xxxProvider%20%3C-%20xxx
.. etc.
XCtrlIt is not declared in HTML with a directive ng-controller, but is defined only in the routing configuration.
source
share