[英]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');
});
Promise chain should always have return object from .then
to continue the promise chain 承诺链应始终具有。的返回对象
.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');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.