Angularjs循环异步无效调用

Angularjs循环异步无效调用,angularjs,asynchronous,Angularjs,Asynchronous,我这里有一段代码 A preloaded list through a rest call... $scope.loadedList = [{a:1,flag:false},{a:2,flag:false},{a:3,flag:false}]; angular.forEach($scope.loadedList, function( value , key ) { if (value.a < 3){ ...rest call that changes the fla

我这里有一段代码

A preloaded list through a rest call...

$scope.loadedList = [{a:1,flag:false},{a:2,flag:false},{a:3,flag:false}];

angular.forEach($scope.loadedList, function( value , key ) {
    if (value.a < 3){
      ...rest call that changes the flag to true at database, with void return}

    return $scope.loadedList.length; --> This is 3 and it's ok
}).then(_loadedListLength){
    ...a rest call to get the list again, with falg = false
问题是循环中的那些调用是无效的

如果我必须用一个问题来总结这个问题:

在执行对服务器的另一个调用之前,如何等待循环中一系列异步void调用的完成


谢谢

尽管您的请求“没有”返回值,但如果确定,它将返回
200
。因此,如果使用
$q.all(..)
则只有在所有承诺都以成功状态完成时,才会出现成功回调。您尝试这种方法时出现了什么问题?我不清楚。你能展示一下你填充
promises
数组的代码吗?谢谢Luiz,我刚刚说到了你建议我的要点。实际上,我需要在完成调用之后完成调用的数量,如果它们返回void,这并不重要,我仍然在数组中有一个void响应对象用作计数。谢谢你的帮助
$q.all(promises).then(doSomethingAfterAllRequests);