从下拉列表中的Yahoo weather API获取数据,点击城市后显示所选城市的天气

时间:2015-11-01 04:19:54

标签: angularjs node.js mongodb api

数据库查询

var query = new YQL('select * from weather.forecast where (location = '+req.params.locationNumber+')');

以下是HTML

<select ng-model="city" class="form-control" ng-options="city.location as city.cityName for city in cities" ng-init="city=''" data-ng-click="getWeather(city)">
                  <option value="">Select City</option>
                </select>

以下是Angular.js

    $scope.getWeather = function(data){
        if(data){       
            appService.get({url: 'weather', id: data}).$promise.then(function(data) { 
                $scope.weather = data.temp;
            }).catch(function(error){
                growl.addErrorMessage('oops something went wrong');
            });
        }
    }

0 个答案:

没有答案