0

Making an Async post request inside .forEach is causing me a lot of problems. With or without the use of $resource I will get data lose. Or maybe the server just can't get all the requests processed at the same time, I don't really know.

Here is the code i'm using:

   // WHEN THE PROBLEM STARTS
angular.forEach($scope.item, function(item, i){
    var thisItemInv = {
        "title": $scope.item[i].title,
        "host_id": status.id;
    };
    // POST REQUEST
    $Http..
    or the same result with
    $resource
});

I can get just one result right, and the rest is incomplete. I get around this using jquery ajax with async to false, but I would like to avoid jquery and fix this the angular way

sebastiannm
  • 565
  • 1
  • 5
  • 14
  • Are you watching the chrome networking tab or firebug, or some other network proxy to see what is happening with the requests? – shaunhusain Sep 07 '13 at 17:12
  • @shaunhusain yes I do, and the request are completed and I get a response for all of them. But the result is incomplete. Only when using async to false on jquery I get it right – sebastiannm Sep 07 '13 at 17:15
  • 1
    Please post your complete `$http` or `$resource` calls. It sounds more like a scoping issue or possibly how you're handling the responses. For a sanity check, I make plenty of parallel async ajax calls using angular without an issue. I'd encourage you to look into `$q.all()` if you're waiting for them to all complete. – Kevin Stone Oct 08 '13 at 08:03

0 Answers0