2016-07-05 44 views
0

我是Angularjs的新手。我想發送兩個GET查詢以獲得來自兩個URL的響應,但我只能從第一個URL(它在控制檯的屏幕截圖中顯示)獲得響應,並且無法在網頁上顯示它。

任何人都可以幫助我解決這個問題嗎?非常感謝。

screenshot of code

screenshot of console

+1

沒有人可以幫助你,而不穿通你的代碼... – Rayon

+2

你應該一個將代碼添加到您的問題中,而不是隻發佈屏幕截圖。 –

+0

將'array'作爲'$ q.all'的參數傳遞 – Rayon

回答

1

試試這個:

var promises = []; 
promises.push($http.get("url1")); 
promises.push($http.get("url2")); 

$q.all(promises).then(function (data){ 
    $scope.course = data[0]; 
    $scope.location = data[1]; 
} 
1

你需要把你的網址,在一個陣列中$q.all

$q.all([$http.get("url1"),$http.get("url2")]).then(function (data){ 
    console.log(data[0]); //response from 1st url 
    console.log(data[1]); // response from 2nd url 
});