<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="angular-1.3.0.js"></script>
<script type="text/javascript">
var app=angular.module("myApp",[]);
app.value("url","https://free-api.heweather.com/v5/weather?city=beijing&key=545d63e185fc48169a43cbabba6e74d2");
app.controller("myCtrl",function($scope,$http,url){
$http.get(url).then(function(response){
$scope.city=response.data.HeWeather5[0].basic.city;
$scope.now=response.data.HeWeather5[0].now.cond.txt;
},function(response){
console.log(response.status)
});
});
app.controller("myCtrl1",function($scope,$interval,$timeout){
$interval(function(){
$scope.shijian=shijian();
},1000);
});
var shijian=function(){
return new Date().toLocaleDateString()+" "+new Date().toLocaleTimeString();
};
</script>
</head>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<div>城市:{{city}}</div>
<div>城市:{{now}}</div>
</div>
<div ng-controller="myCtrl1">
<div>{{shijian}}</div>
</div>
</body>
</html>
城市天气和现在时间
最新推荐文章于 2020-05-18 22:31:15 发布