使用 $q.all 使同步 http 调用不起作用 angularjs

using $q.all for making synchronous http calls not working angularjs

我遇到了以下问题,无法继续。我尝试了不同问题中发布的一些解决方案,但无法正常工作

在我的控制器中,我有一个 $scope.init() 函数。我有一个 for 循环,它调用一个函数来对不同的 url 进行 http.get 调用,每个 url 取决于前一个调用的数据,所以我需要它是同步的

$scope.init = function() {
    decodedURL = $routeParams.url;

    //evaluate some variables, ampIndex is > -1 here

    for( var i=0; ampIndex > -1; ++i)
    {
        decodedURL = decodedURL.substring(ampIndex+1, decodedURL.length);
        ampIndex = decodedURL.indexOf("&");

        $scope.getNextList(i);
        /* above function call makes the http.get call to the currentURL based on
           decodedURL, and the data is stored in variable[i+1], so for the next
           iteration, the calls should be synchronous
        */

        $q.all(asyncCall).then(function (data) {var j;} );
        /* I wrote the above dummy statement so that it is executed only after
           http.get in $scope.getNextList() function is successful, but it is
           not working 
        */
    }
};


$scope.getNextList = function(index) {

    // $currentURL is calculated
    var hello = _helpers.server.http($http, $scope.currentURL) {
        .success( function(response) {
        })
        .error( fucntion(errResponse) {
        });
    asyncCall.push(hello);
};

我该如何解决这个问题?

按照这些思路怎么样?

http://plnkr.co/edit/pjWbNX1lnE2HtaNs1nEX?p=preview

$scope.init = function ( ){
  for (var i=0; i < 10; i++) {
    $scope.getNextList(i) // push calls into array
  };

  var index = 0;
  function makeCall() {
    $scope.asyncCall[index]
    .success(function(data) {
      if (index < $scope.asyncCall.length - 1) {
        console.log(index);
        index += 1;
        makeCall();
      }
      else {
        console.log(index); // last call
      }
    })      
  }

  makeCall();
};