javascript - making synchrnous http call in a for loop angularjs -


i have array of url , requirement have make http.get requests in synchronous manner. after first url call successful, second 1 should called

for(var in urlarray) {     /*do operations , next url*/     $scope.alpha(newurl); }  $scope.alpha = function (newurl) {     $http.get(newurl) // these calls should synchronous     .success(function () {     })     .error(function () {     }); } 

how do this?

i assuming want call them sequentially, in case, can use recursion, call function inside .success callback

var currenturl; // calculate teh currenturl $scope.alpha(currenturl);  $scope.alpha = function (newurl) {     $http.get(newurl) // these calls should synchronous     .success(function (response, status, headers, config) {         //get response         //generate new currenturl per need          //keep break condition, exit         $scope.alpha(currenturl);      })     .error(function () {     }); } 

2) alternately can $q, deferred calls achieve this

hope helps


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -