Skip to content

Instantly share code, notes, and snippets.

@jbmartinez
Created July 26, 2015 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbmartinez/d54776e49f0af4f3726b to your computer and use it in GitHub Desktop.
Save jbmartinez/d54776e49f0af4f3726b to your computer and use it in GitHub Desktop.
Processing an array when data comes from several asynchronous requests in angular.js
var url = "http://api.mysite.com/json"
// arr is an array containing values for a parameter
$q.all(arr.map(function(element) {
// return promises
return $http.get(url, {param: element});
})).then(function(data) {
// do something with data
// data is an array of responses
console.log(data);
var transformedData = data.map(function(item) {
// optional transform
var transform = someFunction();
return transform;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment