Created
July 26, 2015 20:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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