Angular JS:第一个小案例
<!DOCTYPE html> <!-- 作者:[email protected] 时间:2018-05-07 描述: ng-app 声 明 所 有 被 它 包 含 的 元 素 都 属 于 AngularJS 应 用 --> <html ng-app="app"> <head> <meta charset="utf-8" /> <title>Angular JS Hello World!</title> <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script> </head> <body> <div ng-controller="mainController"> <h1>Hello {{ message }}</h1> </div> <div ng-controller="myController"> <h1>当前时间 : <font color="orangered">{{ clock }}</font></h1> </div> </body> <script> var myApp = angular.module('app', []); myApp.controller('mainController', function($scope) { $scope.message = "Plunker"; }); myApp.controller('myController', function($scope, $timeout) { var updateClock = function() { var da = new Date(); var year = da.getFullYear()+'年'; var month = da.getMonth()+1+'月'; var dates = da.getDate()+'日'; var now = year+month+dates; var s = da.getHours()+'时'; var f = da.getMinutes()+'分'; var m = da.getSeconds(); now = now +s+f+m; $scope.clock = now; $timeout(function() { updateClock(); }, 1000); }; updateClock(); }); </script> </html>