title: AngularJS, promise with recursive function
body: <p>I'm trying to use the AngularJS promise/then with a recursive function. But the then-function is not called (none of the error-, success-, notify-callbacks gets called).</p>
  
  <p>Here is my code:</p>
  
  <p><strong>recursive function</strong></p>
  
  <pre><code>loadSection2 = function() {
  
      var apiURL = "http://..."
  
      var deferred = $q.defer();
  
      $http({
          method: "GET",
          url: apiURL
      }).success(function(result, status, headers, config) {
          console.log(result);
          loadCount++;
          if(loadCount &lt; 10) {
              newSectionArray.push(result);
              loadSection2(); 
          } else {
              loadCount = 0;
              deferred.resolve();
              return deferred.promise;
          }
      }).error(function() {
          return deferred.reject();
      });
      deferred.notify();
      return deferred.promise;
  };
  </code></pre>
  
  <p><strong>then</strong></p>
  
  <pre><code>loadSection2().then(function() {
      console.log("NEW SECTIONS LOADED, start adding to document");
      addContent();
  }, function() {
      console.log("ERROR CALLBACK");
  }, function() {
      console.log("NOTIFY CALLBACK");
  }).then(function() {
      loadScrollActive = false;
  });
  </code></pre>
  
  <p>I think, the then has to get the first notify-callback at least. But there is no callback.
  Is then not working with recursive function?</p>