$timerout和interval服务
<body ng-app="app" ng-controller="xmgController">
<!--ng-bind :使用给定的变量或表达式的值来替换 HTML 元素的内容-->
<p ng-bind="name"></p>
<!--间隔2s 执行任务-->
<p ng-bind="dateTime | date:'yyyy-MM-dd hh:mm:ss Z'"></p>
<!--点击按钮停止定时器-->
<button ng-click="stop()">停止计时</button>
</body>
<script src="js/angular.js"></script>
<script>
//1.创建模块
var app = angular.module('app', []);
//2.创建控制器
//行内式注入
app.controller('xmgController', ['$scope', '$timeout', '$interval',function ($scope, $timeout, $interval) {
$scope.name = "SK";
//延时执行任务
$timeout(function () {
$scope.name = "V587";
}, 3000);
//间隔指定时间执行任务
$scope.dateTime = new Date();
var timer = $interval(function () {
$scope.dateTime = new Date();
}, 1000);
//点击按钮停止定时器
$scope.stop = function () {
alert('aaa');
$interval.cancel(timer);
}
}]);
//3.绑定模块 ng-app="app"
//4.绑定控制器 ng-controller="xmgController"
</script>