我试图在控制器中注入由服务解析的这个fieldsList变量,但是我遇到了错误:
projectApp = angular.module('projectApp', ['ui.router']);
projectApp.config(function($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider.state('initial', {
url: '/',
template: 'Hi !'
})
.state('fields', {
url: '/customers/fields',
resolve: {
fieldsList: function (fieldService) {
return fieldService.getFields();
}
},
views: {
'': {
controller: 'fieldController',
templateUrl: '/static/app/customers/pages/fields.html'
},
'list@fields': {
controller: 'fieldListController',
templateUrl: '/static/app/customers/pages/fields.list.html'
}
}
})
//$locationProvider.html5Mode(true);
});
//控制器
projectApp.controller('fieldListController', ['$scope, $http', 'fieldsList', function($scope, $http, fieldsList) {
this.fieldsList = fieldsList;
console.log(this.fieldsList);
}]);
//错误:
angular.min.js:124 Error: [$injector:unpr] http://errors.angularjs.org/1.6.6/$injector/unpr?p0=%24scope%2C%20%24httpProvider%20%3C-%20%24scope%2C%20%24http%20%3C-%20fieldListController
at angular.min.js:7
at angular.min.js:46
at Object.d [as get] (angular.min.js:43)
at angular.min.js:46
at d (angular.min.js:43)
at e (angular.min.js:44)
at Object.instantiate (angular.min.js:44)
at angular.min.js:95
at Object.<anonymous> (angular-ui-router.min.js:11)
at angular.min.js:17 "<div class="row mt-4 ml-1 mr-1 ng-scope" ui-view="list">"
任何人都可以看看这个,请说出我做错了什么? PS:我可以在webservice上记录数据。所以至少服务似乎有效。
答案 0 :(得分:1)
这只是因为你的控制器的注入数组有'$scope, $http'
作为一个字符串
拆分这两个依赖项:
['$scope', '$http', 'fieldsList', function($scope, $http, fieldsList) {
这应该可以解决错误。