Posted in Javascript onDecember 27, 2017
本文实例讲述了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程序设计有所帮助。
Angular实现的简单查询天气预报功能示例
- Author -
当爱0201声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@