I have this code:
GamesStatsService.query({ level: 1 }).$promise.then(function(consoles) {
$scope.consoles = consoles;
_.each(consoles, function(c) {
GamesStatsService.query({ consoleName: c.id, level: 2 }).$promise.then(function(regions) {
c.regions = regions;
_.each(regions, function(r) {
GamesStatsService.query({ consoleName: c.id, regionName: r.id, level: 3 }).$promise.then(function(subRegions) {
r.subRegions = subRegions;
console.log('(maybe) finished loading, notify subscriber!');
});
});
});
});
});
Now I want to know when everything is resolved, and I'm guessing I should use $q.all() for this. The problem is that the calls are dependant on the previous steps output and since I'm doing the calls on each previous output, where should the promise(s) be placed?
The levels are always 3 deep so recursion shouldn't be necessary.
Any kind of input would be appreciated!