我是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;
});
});
答案 0 :(得分:2)
我认为这是你正在寻找的东西:
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'