Angularjs loop trought $http.post

前端 未结 3 636
死守一世寂寞
死守一世寂寞 2021-01-06 23:51

When I loop through the $http post service for Angularjs

for (var i = 0; i < $scope.tagStyles.length; i++) {
  $scope.profilTag.tag = $scope.tagStyles[i].         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 00:16

    You may want to use AngularJs promise API.

    var promiseArray = [];
    
    for (/*your loop statements*/) {
     promiseArray.push($http.post('/url', $scope.var));
    }
    
    $q.all(promiseArray).then(function(dataArray) {
        // Each element of dataArray corresponds to each result of http request.
    });
    

    See Usage->returns section in $http service docs, to understand what is returned via dataArray parameter.

提交回复
热议问题