<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>AngularJS 内置服务</title> <script src='./angular.min.js'></script> </head> <body ng-app="App"> <div ng-controller="DemoCtrl"> <p>当前时间为: {{now|date:'yyyy-MM-dd hh:mm:ss'}}</p> <button ng-click="stop()">停止</button> </div> <script> var App = angular.module('App', []); App.controller('DemoCtrl', ['$scope', '$timeout', '$interval', function ($scope, $timeout, $interval) { $scope.now = new Date(); var timer = $interval(function () { $scope.now = new Date(); }, 1000); $scope.stop = function () { $interval.cancel(timer); } }]) </script> </body> </html>