我在我的项目中使用AngularJs.我必须进行多个http调用,然后将合并的结果返回到我的视图.如何使用AngularJs实现这一目标?
请告诉我,因为我不是AngularJs的专家,需要一个正确的方法来解决这个问题.
使用promise API:
var wheatherPromise = $http.get(...);
var timePromise = $http.get(...);
var combinedPromise = $q.all({
wheather: wheatherPromise,
time: timePromise
})
combinedPromise.then(function(responses) {
console.log('the wheather is ', responses.wheather.data);
console.log('the time is ', responses.time.data);
});
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅文档
| 归档时间: |
|
| 查看次数: |
2234 次 |
| 最近记录: |