您应该从
getResponders函数返回promise ,当它被解析后,它应该
response.data从该函数返回。
厂
var myService = angular.module("xo").factory("myService", ['$http', function($http) { return { getResponders: function() { return $http.get('myUrl') .then(function(response) { console.log("coming from servicejs", response.data); //return data when promise resolved //that would help you to continue promise chain. return response.data; }); } };}]);同样在控制器内部,您应该调用factory函数,并
.then在
getRespondersservice函数解析该
$http.get调用并将其分配
data给
$scope.gotData
码
$scope.goData = function(){ myService.getResponders.then(function(data){ $scope.gotData = data; }); };


