I'm trying to create an Ionic app and for this I have to make some HTTP GET request inside a for loop but it appears that angular does not wait for the data before showing them.
Here is a code I'm using.
$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");
});
The first HTTP get is done and the data can be show within the foreach but when I try to add additionnal data to the original ones with a second get request nothing is created or sometimes only the last value is shown for every one.