<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>动态时间例子</title>
<script src="js/angular.min.js"></script>
<script>
var app=angular.module("timeDemo",[]);
app.controller("timeCtrl",function($scope){
//获取当前时间
var now1=new Date();
//让时间在页面显示
$scope.Now=now1.getHours()+‘:‘+now1.getMinutes()+‘:‘+now1.getSeconds();
//写一个方法获取当前时间
$scope.SetTimer=function(){
//angularJs的特性,需要手动把变化映射到html元素上面
$scope.$apply(function(){
var now=new Date();
$scope.Now=now.getHours()+‘:‘+now.getMinutes()+‘:‘+now.getSeconds();
});
};
//每隔1秒刷新一次时间
$scope.SetTimerInterval=setInterval($scope.SetTimer,1000);
});
</script>
</head>
<body ng-app="timeDemo" ng-controller="timeCtrl">
当前时间为:{{Now}}
</body>
</html>