时间:2021-02-08 09:33:03 | 栏目:AngularJS | 点击:次
本文实例讲述了Angular实现的简单查询天气预报功能。分享给大家供大家参考,具体如下:
先来看看运行效果:
具体代码如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="angular.min.js"></script> </head> <body ng-app="myApp" ng-controller="siteCtrl"> <div > <input type="text" ng-model="city2" value="beijing"> <button ng-click="check()">btn</button> <p>未来3天的天气情况</p> <ul ng-show="toggle"> <li> {{city.basic.city}};<span>跟新时间:{{city.basic.update.loc}}</span> <p>气温:{{city.now.tmp}}deg</p> <p>wind:{{city.now.wind.dir}}</p> </li> </ul> </div> <script> var url1='https://free-api.heweather.com/v5/weather?city='; var url3='&key=545d63e185fc48169a43cbabba6e74d2'; var app = angular.module('myApp', []); app.controller('siteCtrl', function($scope, $http) { $scope.toggle=false; $scope.check=function(){ $scope.toggle=true; var url2=$scope.city2; $http({ url:url1+url2+url3 }).then(function(data){ console.log(data.data); $scope.data=data.data; $scope.city=$scope.data.HeWeather5[0]; }); }; }); </script> </body> </html>
更多关于AngularJS相关内容感兴趣的读者可查看本站专题:《AngularJS指令操作技巧总结》、《AngularJS入门与进阶教程》及《AngularJS MVC架构总结》
希望本文所述对大家AngularJS程序设计有所帮助。