팩토리에서 데이터를 반환하고 출고시 로깅을 시도하면 정확한 데이터가 출력되지만 컨트롤러에 일단 전달되면 항상 정의되지 않습니다. 컨트롤러 내부에 내 공장 논리가 있으면 제대로 작동합니다. 여기에 실종 된 간단한 무언가가 틀림 없어?컨트롤러에 대한 공장 데이터 반환 항상 정의되지 않음
응용 프로그램
var app = angular.module('app', []);
app.controller('animalController', ['$log', '$scope', 'animalResource', function($log, $scope, animalResource) {
$scope.list = function() {
$scope.list = 'List Animals';
$scope.animals = animalResource.get(); // returns undefined data
$log.info($scope.animals);
};
$scope.show = function() {};
$scope.create = function() {};
$scope.update = function() {};
$scope.destroy = function() {};
}]);
app.factory('animalResource', ['$http', '$log', function($http, $log) {
return {
get: function() {
$http({method: 'GET', url: '/clusters/xhrGetAnimals'}).
success(function(data, status, headers, config) {
//$log.info(data, status, headers, config); // return correct data
return data;
}).
error(function(data, status, headers, config) {
$log.info(data, status, headers, config);
});
},
post: function() {},
put: function() {},
delete: function() {}
};
}]);
로그인 정보 서비스
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
200 function (name) {
if (!headersObj) headersObj = parseHeaders(headers);
if (name) {
return headersObj[lowercase(name)] || null;
}
return headersObj;
} Object {method: "GET", url: "/clusters/xhrGetAnimals"}
'반환 데이터를 그것을 할, '성공 호출 내에서 back은'get' 함수에서 아무 것도 반환하지 않습니다.'return $ http ({method ...'. 각도 문서 사이트 – charlietfl
에 대한 지침서를 읽으십시오. $ http 앞에 수익을 추가하십시오. 대답을하고 악이 그것을 받아 들인다. 감사 – dynamo