我是 AngularJS 的新手,我想在 AngularJS 中获取多个城市的数据。
这是代码:
var app = angular.module('jsbin', []);
app.controller('DemoCtrl', function($http) {
var vm = this;
var vm1 = this;
var URL = 'http://api.openweathermap.org/data/2.5/forecast/daily';
var request = {
method: 'GET',
url: URL,
params: {
q:'',
mode: 'json',
units: 'imperial',
cnt: '7',
appid: '4e1869d8da618fde99e84483*******'
}
};
$http(request)
.then(function(response) {
vm.data = response.data.list ;
console.log(response.data);
}).
catch(function(response) {
vm.data = response.data;
});
});
最佳答案
我认为这就是您正在寻找的:
var URL = http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743&units=metric
来源:http://openweathermap.org/current#severalid
编辑:
如果端点没有为您切断它,您可能必须使用 $q.all 来执行多个 'http://api.openweathermap.org/data/2.5/forecast/daily'
并行
关于angularjs - 如何在angularjs中使用openweathermap api获取多个城市的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39053305/