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

来源:互联网 发布:java oa项目源码 编辑:程序博客网 时间:2024/06/06 22:42

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>

阅读全文
0 0
原创粉丝点击