Я пытаюсь использовать предложение AngularJS/then с рекурсивной функцией. Но тогда функция не вызывается (ни один из вызовов error-, success-, notify-callback не вызван).
Вот мой код:
рекурсивная функция
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 < 10) {
newSectionArray.push(result);
loadSection2();
} else {
loadCount = 0;
deferred.resolve();
return deferred.promise;
}
}).error(function() {
return deferred.reject();
});
deferred.notify();
return deferred.promise;
};
затем
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;
});
Я думаю, что тогда должен получить, по крайней мере, первый ответ-обратный вызов. Но обратного вызова нет. Не работает ли с рекурсивной функцией?