Angular chaining promises from foreach loop

后端 未结 2 518
天涯浪人
天涯浪人 2021-01-23 18:34

I have an array of photo files that needed to upload to Azure Cloud Storage, and i using foreach loop to call upload as below:

$scope.savetemplate = function ()          


        
2条回答
  •  礼貌的吻别
    2021-01-23 19:00

    In the success callback of the upload function, after pushing the path:

    imagePathsArray.push(resp.data);
    if(imagePathsArray.length == $scope.filesimage.length){
      pushtoDatabase();
    }
    

    Inside pushtoDatabase call the $http({ .... });

    NOTE : You might like to consider the probability of the upload getting failed. In that case you can work-around using a counter of failed files say failCounter , and then inside the if check for the condition

    if ((imagePathsArray.length + failCounter) == $scope.filesimage.length){....}

提交回复
热议问题