2016-02-09 113 views
0

值后,我有一些代码,如下图所示:无法读取角度推

$scope.offer = []; 
angular.forEach($scope.details, function (product) { 
    SomeAPI.ById.query({ product: product.id }, function (response) { 
    $scope.offer.push(response); 
    }); 
    return $scope.offer; 
}); 
console.log($scope.offer); 

为什么控制台日志仍然没有把“[]”? 在页面上,{{ offer }}正确显示值。

+0

可能重复[如何返回来自异步调用的响应?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response -from-一个异步呼叫) – Tushar

回答

0

您的API是异步函数

SomeAPI.ById.query({ product: product.id }, callback); 
console.log('query is still running. callback will be done later') 

上面的回调会被调用后后异步函数完成。您的console.log立即调用