$q.all - 访问个人承诺结果?

$q.all - access individual promise result?

我对 $q angular promises 有点陌生。这是我的代码结构:

$q.all(promises).then(function(results) {
    results.forEach(function(data, status, headers, config) {
        console.log(status);
    });
    $scope.saveDocumentCaseState();
}, function errorCallBack(response) {
    console.log('error while mass update case entries');
    console.log(response);
    $scope.submitToWsSuccessful = 2;
});

当每个承诺在下一个承诺之前执行时,是否有可能访问每个承诺的结果

因此,假设您从名为 promiseFactory 的 angular 工厂收到一个包含任意数量承诺的数组:

var promises = promiseFactory.getPromises(); // Returns an array of promises

promises.forEach(function(p){
  p.then(promiseSuccess, promiseError);

  function promiseSuccess(){
    // Do something when promise succeeds
  }

  function promiseError(){
    // Do something when promise errors
  }
});

$q.all(promises).then(allSuccess, allError);

function allSuccess(){
  // All calls executed successfully
}

function allError(){
  // At least one of the calls failed
}