So I have a method in a angularjs server that is calling a method that returns a promise for each method in a array. I am using underscore _each to loop through the array. I want to wait until the entire array is processed before I call the final line of code in the method..
So...
function ProcessCoolStuff(coolStuffs)
{
var stuff = [];
_.each(coolStuffs, function(coolStuff)
{
//Some method using $q to return
makeStuffCooler(coolStuff).then(function(coolerStuff)
{
stuff.push(coolerStuff);
});
});
//Maybe Call a Display Method, or call event ect..
ShowAllMyCoolStuff(stuff);
}
This of course does not work.. the loop completes and calls 'ShowAllMyCoolStuff' before the makeStuffCooler is done for each item. So.. what is the correct way to interact with the async method so my ShowAllMyCoolStuff method will wait until the collection is populated? This may be my lack of experience with $q and promises in general, but I am stuck. Thanks in advance.