0
內呼籲環路我試圖創建一個離子應用,爲此我必須做出內部一些HTTP GET請求循環,但似乎角之前不會等待數據展示他們。API的角度
這是我正在使用的代碼。
$http.get(ApiUrl.get() + '/Threads' + '?access_token=' + $scope.userToken + filterString + "&filter[order]=created%20desc")
.success(function(data, status, headers, config) {
var i=0;
for(thread in data)
{
$scope.threadObj = data[i];
var threadId = $scope.threadObj.id;
$scope.threadPostNumber;
//On récupére chaque nombre de post
$http.get(ApiUrl.get() + '/Threads/' + threadId + '/posts/count' + '?access_token=' + $scope.userToken)
.success(function(data, status, headers, config) {
$scope.threadPostNumber = data.count;
})
.error(function(data, status, headers, config) {
alert("Connection error, please try again.");
$location.path("/app/carte");
});
$scope.threadObj.count = $scope.threadPostNumber;
$scope.threads[i] = $scope.threadObj;
i++;
}
})
.error(function(data, status, headers, config) {
alert("Connection error, please try again.");
$location.path("/app/carte");
});
第一HTTP GET完成並且數據可以在foreach內展示,但是當我嘗試其它附加數據添加到原有的以創建第二GET請求沒有或者有時候只有最後一個值顯示每一個。
不幸的是,你不能像這樣使用$ http。 http://stackoverflow.com/a/17366158/3980115 – Vlad274 2015-02-10 22:12:14
@ Vlad274,有沒有辦法做到這一點,沒有localstorage? – PeterFour 2015-02-10 22:15:16