I have an issue with an Angular app.
I have an array that contains langs shortcodes ('en', 'fr', ...). And basically, I want Angular to loop on that array and make HTTP get request on each value.
for (var i in $scope.langs) {
console.log($scope.langs[i].shortName);
$http.get($scope.appURL + $scope.langs[i].shortName + '/api/products/?format=json&resto='+ $scope.restoID)
.then(function(res){
$scope.products = angular.fromJson(res.data);
window.localStorage.setItem("products-"+$scope.langs[i].shortName, JSON.stringify(res.data));
$scope.products = JSON.parse(window.localStorage.getItem("products-"+$scope.langs[i].shortName));
console.log('LANG = '+ $scope.langs[i].shortName, $scope.products);
});
}
The first log shows :
fr
en
Great ! The last log is thrown twice (I've got 2 langs in my array), great too.
The problem is that in the loop, the log shows the same language in both case, when I should have one fr/api/... and one en/api/... It always log 2 en/api/...
I don't know if it's clear... Any idea ?