I have this code:
// HTTP request
$http.get(dataSource).
then(function(data, status, headers, config) {
// Products array
var products = [];
// Loop through each array value
for (var slug in data.data){
var product = data.data[slug];
$http.get('content/products/' + product + '.json').then(function(response){
products.push(response.data);
$scope.products = products;
}).catch(function(){
console.log('there was an error');
});
}
}).catch(function(){
console.log('there was an error');
});
The issue is that sometimes the product scope array items do not arrive always in the same order they are requested.
I need the products $scope to loop through the array and only when the response has been pushed to the array:
products.push(response.data);
that is finally assigned to the variable $scope.products.
Any help with modifying my current HTTP request?