Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Angular $resource with $q.all()
Message
From
08/05/2014 06:09:51
 
 
To
All
General information
Forum:
Javascript
Category:
Tools/Libraries
Title:
Angular $resource with $q.all()
Miscellaneous
Thread ID:
01599720
Message ID:
01599720
Views:
58
Below are two versions of code that should do the same thing. X,Y and Z are angular $resource's . First example works as expected but on the second example the .then() fires before results are back. In this example there's no advantage in method 2 but in practice I want to build the actions[] dynamically.

I've seen examples of the second method on the web and also versions which built the array using the equivalent of just X.doSomething(a) - i.e. not the $promise. The latter doesn't seem correct to me but it doesn't work either.

Can anyone suggest a solution that works?
//This works
$q.all([
    X.doSomething(a).$promise,
    Y.doSomething(b).$promise,
]).then(function (result) {
});

//This doesn't
var actions = [];
actions.push(X.doSomething(a).$promise);
actions.push(Y.doSomething(b).$promise);

$q.all([actions]).then(function (result) {
    //Here before results obtained
});
Should mention that in the second approach nothing hits the server - ever.
Next
Reply
Map
View

Click here to load this message in the networking platform