Taylorsuk
Taylorsuk

Reputation: 1449

AngularJS : Adding variable into a chain of promises

I am learning promises and am struggling with the following.

Three functions are being run in this case.

//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');
});

Upvotes: 2

Views: 128

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

Promise chain should always have return object from .then to continue the promise chain

//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');
});

Upvotes: 3

Related Questions