javascript - looped nested $http js functions -


i have 2 javscript async $http funtions: using angular js in nested way create table dynamically.

i want way execute these functions synchronously.

right now, j loop executes on initial value of resultb. once table compiled fuctb gets executed values of i.

$scope.funca = function() {   $http({     method : 'get',     url : url,                     }).then(function successcallback(response) {     $scope.resulta = response.data;     //process based on $scope.resulta     (var = 0; < $scope.resulta .length; i++){       $scope.funcb($scope.resulta[i][0]);       for(j=0; j<$scope.resultb .length; j++){         //process based on $scope.resultb       }                          }      $compile(/* document element*/);    }, function errorcallback(response) {     console.log(response.statustext);   }); }  $scope.funcb = function(k){   $http({     method : 'get',     url : url+k     data: k ,   }).then(function successcallback(response) {     return $scope.resultb = response.data;   }, function errorcallback(response) {     console.log(response.statustext);   }); } 

$scope.funcb = function(i) {      // return promise      return $http({....          data: ;          $scope.resultb = response.data;       }; }   $http{..... $scope.resulta =response.data; for(var =0; i< $scope.resulta.length; i++{   process based on value   $scope.funcb(i).then(function() {   // execute part after promise completed (request b has ended , returned result)   for(var j =0; j<$scope.resultb.length;j++{       process based on , j;       }    }    compile(the document element); }); } 

please check tutorial on promises understand what's going on here, e.g. http://liamkaufman.com/blog/2013/09/09/using-angularjs-promises/ there plenty of these on internet...


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -