Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Angular $resource with $q.all()
Message
De
08/05/2014 06:09:51
 
 
À
Tous
Information générale
Forum:
Javascript
Catégorie:
Outils/Librairies
Titre:
Angular $resource with $q.all()
Divers
Thread ID:
01599720
Message ID:
01599720
Vues:
59
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.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform