Sharing my code snippet below:
function createObject(title, array){
this.title = title;
this.array = array;
}
//$scope.objects is an array of objects
function mapPromise(title, promise){
this.title= title;
this.promise = promise;
};
var fetchAllPromises = function(){
var promises = [];
angular.forEach($scope.objects, function(object) {
urlPath = <dynamicurl>+object.title;
var promise = $http({
url : urlPath,
method: 'GET'
});
promises.push(new mapPromise(object.title, promise));
});
return $q.all(promises);
};
I am facing a challenge when trying to access the JSON response received from the service in the below .then block. Any suggestions on how I can achieve this?
fetchAllPromises.then(function(data){
angular.forEach(data, function(promiseData){
var title = promiseData.title;
var responseData = promiseMap.<?> --> How do I retrieve the JSON data here?
<I need to assign $scope.objects.array to data returned by the promise based on each object's title attribute>
});
});
Looking for guidance on this matter as I'm still new to working with promises and AngularJS in general.