2

Я изучаю обещания и борюсь со следующим.AngularJS: Добавление переменной в цепочку обещаний

В этом случае выполняются три функции.

//returns an search query in JSON format 
filterSearch() 

    // searches Parse.com and returns an array of values 
    .then(performSearch) 

    // I am passing the array of values to exerciseSearch and a another value (term - string) 
    .then(function(result) { 
    exerciseSearch(result, term); 
    }) 

    // The results from the search is displayed in scope. 
    .then(function(exercises) { 
    $scope.allExercises = exercises; 

    }, function(error) { 
    console.log('error'); 
}); 
+0

Вы, вероятно, означало 'вернуть exerciseSearch (результат, термин)' – Bergi

ответ

3

Promise цепь должна всегда иметь обратный объект из .then продолжить Обещание цепочку

//returns an search query in JSON format 
filterSearch() 

    // searches Parse.com and returns an array of values 
    .then(performSearch) 

    //(term - string) 
    .then(function(result) { 
     return exerciseSearch(result, term); //exerciseSearch should return exercises from fn 
    }) 

    // The results from the search is displayed in scope. 
    .then(function(exercises) { 
    $scope.allExercises = exercises; 
    return exercises; 
    }, function(error) { 
    console.log('error'); 
}); 
+0

Вы уверены, что 'result' вы» Повторное прохождение - это одно из правильного поиска? – Bergi

+2

@ Bergi вы правы .. он должен возвращать 'object', который был создан в' exerciseSearch'. Спасибо за помощь. –

Смежные вопросы