小编jes*_*rma的帖子

5
推荐指数
2
解决办法
6234
查看次数

如何在angularjs中使用openweathermap api获取多个城市的数据?

我是 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;
                            });
});
Run Code Online (Sandbox Code Playgroud)

angularjs openweathermap

2
推荐指数
1
解决办法
6614
查看次数