我在将路由中的resolve参数注入控制器时遇到了问题。我将resolve值设置为一个对象{name: 'Banner', slug: 'banner'}
,但是出现了错误。
App.js
var app = angular.module('CMS', ['fields', 'ngRoute']);
app.controller('ModuleController', ['$http', 'properties',
function($http, properties) {
var module = this;
module.properties = properties;
if (module.properties.slug.length) {
$http.get(module.properties.slug + '.php').success(function(data) {
module.list = data;
});
}
}
]);
app.controller('HomeController', function() {});
app.config(function($routeProvider) {
$routeProvider
// route for the banner page
.when('/banner1', {
templateUrl: 'banner1.php',
controller: 'ModuleController',
resolve: {
properties: function() {
return { name: 'Banner', slug: 'banner' };
}
}
})
.when('/home', {
templateUrl: 'home.php',
controller: 'HomeController'
})
.otherwise({
redirectTo: '/home'
});
});
错误:
Error: [$injector:unpr] http://errors.angularjs.org/1.3.14/$injector/unpr?p0=propertiesProvider%20%3C-%20properties%20%3C-%20ModuleController
at Error (native)
at http://modelo2.desenvolvimento.com/adm/js/angular/angular.min.js:6:417
at http://modelo2.desenvolvimento.com/adm/js/angular/angular.min.js:38:7
at Object.d [as get] (http://modelo2.desenvolvimento.com/adm/js/angular/angular.min.js:36:13)
at http://modelo2.desenvolvimento.com/adm/js/angular/angular.min.js:38:81
at d (http://modelo2.desenvolvimento.com/adm/js/angular/angular.min.js:36:13)
at Object.e [as invoke] (http://modelo2.desenvolvimento.com/adm/js/angular/angular.min.js:36:283)
at $get.w.instance (http://modelo2.desenvolvimento.com/adm/js/angular/angular.min.js:75:451)
at http://modelo2.desenvolvimento.com/adm/js/angular/angular.min.js:58:476
at s (http://modelo2.desenvolvimento.com/adm/js/angular/angular.min.js:7:408) <div ng-view="" class="ng-scope">
/banner1.php
中使用了ng-controller="ModuleController"
。 - New Dev