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>
给大家做一个关于天气的例子
最新推荐文章于 2022-07-03 09:37:28 发布