I have a problem with AngularJS is that, i cannot assign a value to an outer variable in the $http.get method. Here is my code snippet:
.factory('MediaService',['$http', function($http, $q){
return {
getGalleryIds : function() {
galeriURL = 'http://api.tika.gov.tr/www/tr/galleries?';
return $http.get(galeriURL, { cache: true}).then(function(response){
contentIdList = response.data.data;
var contentList = [];
for (i=0;i<contentIdList.length;i++) {
var galeriContentURL = 'http://api.tika.gov.tr/www/tr/galleries/' + contentIdList[i].id;
contentList[i] = $http.get(galeriContentURL, { cache: true})
.then(function(response){
return response.data;
});
}
console.log(contentList);
return contentList;
});
}
}
}]);
My problem is at console.log(contentList); line I'm getting Promise Array because of I cannot assign a value to outer variable.
[Promise, Promise, Promise, Promise, Promise, Promise, Promise, Promise, Promise, Promise]
How can I assign value to var contentList = [ ]; variable in for loop $$http.get and at line console.log(contentList); get Object Array as follows
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]