I am facing a challenge with a page that generates a varying number of $http
requests based on the length of a certain variable. I aim to update the scope with the data only after all requests have been completed. Without relying on jQuery for this project, I seek a solution that does not involve jQuery. Currently, the data is being sent to the scope as each request finishes, which is not the desired behavior.
Below is a snippet of the code I have implemented so far:
for (var a = 0; a < subs.length; a++) {
$http.get(url).success(function (data) {
for (var i = 0; i < data.children.length; i++) {
rData[data.children.name] = data.children.age;
}
});
}
One part that concerns me is the argument required for $q.all()
method, which is not clearly explained in the Angular documentation, leaving me unsure of how to proceed.
$q.all().then(function () {
$scope.rData = rData;
});
I appreciate any assistance in resolving this issue. Thank you.