您的位置:首页 > 其它

给大家做一个关于天气的例子

2017-09-20 14:15 295 查看
myapp.controller("chaxunController",function ($scope,$http) {
var ul1="https://free-api.heweather.com/v5/weather?city=";
var ul2;
var ul3="&key=545d63e185fc48169a43cbabba6e74d2";
$scope.city="阳泉";
$scope.show=false;
$scope.chaxun=function () {
ul2=$scope.city;
$scope.show=true;
$http({
url:ul1+ul2+ul3
}).then(function (data) {
console.log(data);
$scope.city2=data.data.HeWeather5[0].basic.city;
$scope.date=data.data.HeWeather5[0].suggestion.air.txt;
$scope.dir=data.data.HeWeather5[0].now.wind.dir;
$scope.city="";

});

/* $scope.show=false;*/
}
});
<div class="haha4">
<input type="text" ng-model="city"/><button ng-click="chaxun()">查询</button>
<ul ng-show="show">
<li>{{city2}}</li>
<li>{{date}}</li>
<li>{{dir}}</li>
</ul>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: