2

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');
});
1
  • You probably meant return exerciseSearch(result, term) Commented Jul 7, 2015 at 22:54

1 Answer 1

3

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');
});
Sign up to request clarification or add additional context in comments.

2 Comments

Are you sure that the result you're passing on is the one from the right search?
@Bergi you are correct..he should return the object which is been created in exerciseSearch..Thanks for heads up..let me update an answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.