json 파일을로드하기위한 서비스를 작성하려고합니다. 내가 도대체 뭘 잘못하고있는 겁니까?AngularJS (맞춤 서비스가있는 JSON로드 중)
본 서비스
app.service("jsonService", function ($http, $q)
{
var deferred = $q.defer();
$http.get('./assets/json/home.json').then(function (data)
{
deferred.resolve(data);
});
this.getHomeItems = function()
{
return deferred.promise;
}
})
내 컨트롤러
app.controller('homeController', function ($scope, jsonService) {
var promise = jsonService.getHomeItems();
promise.then(function (data)
{
$scope.home_items = data;
console.log($scope.home_items);
});
});
콘솔 오류 : 당신은 dependency injection 누락
가있는 라인에서 당신은 ~ 콘솔 오류를 얻고있다 : $ 범위가 정의되어 있지? –
저는 $ http를 사용하여 JSON 파일을 직접로드 할 수 있다고 확신합니다.이 서비스는 필요하지 않습니다. $ http 메서드는 약속을 반환하고 기본 응답 처리기는 JSON을 구문 분석합니다. –