1 <!DOCTYPE html>
2 <html lang="en" ng-app="myClock">
3 <head>
4 <meta charset="UTF-8">
5 <title>angularJs-clock</title>
6 <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
7 </head>
8 <body>
9 <div ng-app ng-controller="MyController">
10 <h1>现在时间是:<span ng-bind="clock.fulldate"></span></h1>
11 </div>
12 </body>
13 <script>
14 angular.module('myClock',[])
15 .controller('MyController', function($scope){
16 $scope.clock = {};
17 var updateClock = function(){
18 $scope.clock.now = new Date();
19 $scope.clock.fulldate = new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate()+" "+new Date().getHours()+":"+new Date().getMinutes()+":"+new Date().getSeconds()
20 }
21 setInterval(function(){
22 $scope.$apply(updateClock);
23 },1000)
24 updateClock();
25 }
26 )
27 </script>
28 </html>