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

本文介绍了一个使用AngularJS实现的简单天气查询应用。该应用通过$http服务从和风天气API获取指定城市的天气信息,并在界面上展示城市名称、空气质量建议及当前风向等数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值