我正在学习角度1.6.2并且遇到$资源获取错误:[$ injector:unpr] http://errors.angularjs.org/1.6.2/ $ injector / unpr?p0 = HomeServiceProvider%20%3C-%20HomeService
我不确定问题是什么,请帮帮我
controller.js
"user strict";
angular.module('app')
.component('home', {
restrict: 'E',
scope: {},
templateUrl: 'home/home.html',
controller: HomeController
function HomeController(HomeService) {
var vm = this;
vm.message = 'Hi from home page';
vm.users = HomeService.query();
};
service.js
"use strict";
angular
.module('app.services', [])
.factory('HomeService', HomeService);
HomeService.$inject = ['$resource'];
function HomeService($resource) {
return $resource('http://jsonplaceholder.typicode.com/users/:user', {user: '@user'}, {
update: {
method: 'PUT'
}
});
}
app.js
"use strict";
angular.module("app", [
"ui.router",
"ngResource",
"app.service"
])
.config([
"$stateProvider",
"$urlRouterProvider",
"$locationProvider",
function ($stateProvider,$urlRouterProvider ,$locationProvider) {
$locationProvider.hashPrefix('');
$urlRouterProvider.otherwise('/');
$stateProvider
.state('/home',
{
url: "/",
template: "<home></home>"
})
.state('/about',
{
url: "/about",
template: "<about></about>"
})
.state('/contact',
{
url: "/contact",
template: "<contact></contact>"
});
}
]);
答案 0 :(得分:0)
你忘了注入&#34; HomeService&#34;到HomeController?