是的,由于AngularJS的
$http服务是围绕PromiseAPI构建的,因此可以非常优雅地对其进行处理。基本上,对
$http方法的调用会返回一个Promise,您可以使用该
then方法非常轻松地链接Promise
。这是一个例子:
$http.get('http://host.com/first') .then(function(result){ //post-process results and return return myPostProcess1(result.data); }) .then(function(resultOfPostProcessing){ return $http.get('http://host.com/second'); }) .then(function(result){ //post-process results of the second call and return return myPostProcess2(result.data); }) .then(function(result){ //do something where the last call finished });您也可以将后处理和下一个
$http功能组合在一起,这完全取决于谁对结果感兴趣。
$http.get('http://host.com/first') .then(function(result){ //post-process results and return promise from the next call myPostProcess1(result.data); return $http.get('http://host.com/second'); }) .then(function(secondCallResult){ //do something where the second (and the last) call finished });


