2016-07-05 47 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 
});