想在網頁上,顯示當前系統時鐘。 <body ng-app="App2" ng-controller="Ctrl2"> <div ng-bind="ShowTime"> </div> </body> angularjs程式: var app = angular.module('App2', []); ...
<body ng-app="App2" ng-controller="Ctrl2"> <div ng-bind="ShowTime"> </div> </body>Source Code
var app = angular.module('App2', []); app.controller('Ctrl2', function ($scope, $interval, $filter) { $scope.Timer = $interval(function () { var time = $filter('date')(new Date(), 'HH:mm:ss'); $scope.ShowTime = time; },1000); });Source Code
演示: