我是angularJs的新手,我创建了一个在其中使用ui-routing的应用程序,并首先加载Config文件,该文件具有调用组件的默认状态,该组件调用从API获取数据的服务。从plunker example获取此结构。当我运行页面时,它会加载页面 - >配置 - >组件然后抛出错误。当我点击错误消息时,它说它与现在正确地声明注射器有关。找到下面的代码和错误消息。
配置文件(config.js)
var myApp = angular.module('EmpList', ['ui.router', 'ui.router.visualizer']);
alert('config');
myApp.config(function($stateProvider) {
// An array of state definitions
var states = [
{
name: 'hello',
url: '',
// Using component: instead of template:
component: 'Get',
resolve: {
people: function(PeopleService) {
return PeopleService.getAllPeople();
}
}
}
]
// Loop over the state definitions and register them
states.forEach(function(state) {
$stateProvider.state(state);
});
});
组分(people.js)
angular.module('EmpList').component('Get', {
bindings: { people: '<' },
template: '<h3>Some people:</h3>'
})
服务(people.js)
angular.module('EmpList').service('PeopleService', function($http) {
var service = {
getAllPeople: function() {
return $http.get('http://localhost:50164/api/Employee/get').then(function(resp) {
return resp.data;
});
}
}
return service;
})