problem with promise

19 views
Skip to first unread message

samir almorabite

unread,
Jan 17, 2020, 4:06:00 AM1/17/20
to Angular and AngularJS discussion
I call service in foreach , i can execute promise after each call of service instead, to make $q.all in last

Sander Elias

unread,
Jan 17, 2020, 4:16:59 AM1/17/20
to Angular and AngularJS discussion
Hi Samir,

Yes!
That is an answer, I'm not sure about your question, so it might even be a fitting answer ☺
Perhaps you can share some code, so it is more clear what you are asking?

Regards
Sander

samir almorabite

unread,
Jan 18, 2020, 5:33:02 AM1/18/20
to Angular and AngularJS discussion

$scope.listDocuments;
$scope.promises[];
angular.forEach(values, function($scope.listDocuments, document) {
   
    promises.push(myService.downloadDocument(document.url).then(function(document)
    {
        console.debug(document.name);
       
    }).catch(error)
    {
        console.debug(document.name);

    });
       

}


             $q.all(promises);
   
}


myService.downloadDocument{
  var deferred = $q.defer();
$http
    .get('http://download/document')
    .then(function(response) {
      deferred.resolve(response.data);

      }).catch(function(error) {
              deferred.reject(err);
    });
   
}

the problem is , i have service to download many documents, but when a document is failure i want to recover his name in catch console.debug(document.name) i recover only last document in list not document that are failure. I think , the problem is not in service but in how i call service in foreach.
have you any idea..?
Reply all
Reply to author
Forward
0 new messages