什麼是一個乾淨的方式來編寫這樣的代碼?多次,我必須使用先前請求的響應來從不同的來源和表格構建新的URL和彈性搜索查詢。如何在angular.js中編寫更好的順序承諾調用?
$scope.whatIFinallyWant = {};
$http.get(url1).then(function(response1){
// creating new url2 & query with response1
$http.get(url2).then(function(response2){
// creating new url3 & query with response2
$http.get(url3).then(function(response3){
// creating new url4 & query with response3
$http.get(url4).then(function(response4){
// using the final response in UI ...
$scope.whatIFinallyWant = response4;
})
})
})
})
'同步promise' - 承諾是由設計 –