【发布时间】:2016-05-05 14:17:20
【问题描述】:
我有这个函数,其中 GetDataFactory.getDataById(reqData) 是带有 $http 请求的函数并返回正确的数据,当这个数据到达时我想在另一个函数中使用它,但是这种方式一直返回我“Promise {$$state : 对象}"
$scope.getData = function(id) {
var reqData = {
"id": id,
"access_token": $scope.access_token
};
var foo = GetDataFactory.getDataById(reqData).then(function(response) {
var foo = response.data[0];
return foo;
});
console.log(foo); // prints "Promise {$$state: Object}"
return foo;
}
$scope.anotherFunction = function(){
var id;
var bar = $scope.getData(id);
}
我在问如何在 $http 请求成功后返回正确的数据值,然后将其返回到另一个函数并对这些数据做任何我想做的事情?分配给 $scope.foo 类型变量和超时不是一个选项
【问题讨论】:
-
foo.then(function (value) { /* do something with the value */ });
标签: angularjs ionic-framework angular-promise