$timeout&$interval对原生Javascript中的setTimeout和setInterval进行封装 ᤰ̶
var app = angular.module('app',[]); فဳୗٖᤈ
app.controlle('xmgController',['$scope','$timeout','$interval',function ($scope,$timeout,$interva l) {
$scope.name = 'xmg'; ۓձᤈಗ
$timeout(function () { $scope.name="xmg123"; },1000); ۓձᤈಗᳵਧᵍ
var timer = $interval(function () { $scope.dateTime = new Date(); },1000); ਧྊ؊ᰵೲڋᅩ
$scope.stop = function () { alert('aaa'); ؊ྊਧጱਧ $interval.cancel(timer); } }]); <p>{{name}}</p> <p>{{dateTime | date:'yyyy-MM-dd h:m:s'}}</p> <button ng-click="stop()">؊ྊ</button>
记住是$timeout&$interval第一个延时第二个循环
停止循环调用$interval.cancel
angular中:的面试题
1/如何停止一个定时器; 调用cancel方法
2/如何取消数据监听(watch)
网友评论