2016-08-20 29 views
1

我是angularjs中的新成員,我想通過angularjs獲取多個城市的數據。如何在angularjs中使用openweathermap api獲取多個城市的數據?

這裏是代碼:

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

那麼問題是什麼?你已經知道如何去做。 – dfsq

+0

但是在這裏,我只獲取一個城市的數據,但我想要多個城市的數據。 – jesusverma

回答

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'並行

+0

通過這種方式,我們無法獲得多個城市的數據。 – jesusverma

+0

@Jverma每個城市提出更多的請求? – Chris

+0

謝謝@克里斯,但如何使每個城市多個請求? – jesusverma

相關問題