As we all know, Angular’s ??$interval
method is
$interval(fn, delay, [count], [invokeApply], [Pass]);
It returns a promise
, which is generally used to handle different stages. promise.then(success,error,notify)
For example, I use $interval to define a clock and test it
var timer = $interval(function(){
console.log('inner');
},2000,2);
timer.then(success, error, notify);
function success(){
console.log('done');
}
function error(){
console.log('error');
}
function notify(){
console.log('everytime');
The output result of is
outputs
and inner
at the same time every time. What is the difference between everytime
's callback function $interval
and promise's fn
? notify
人生最曼妙的風(fēng)景,竟是內(nèi)心的淡定與從容!
The notify
可能會(huì)被調(diào)用多次,這里只調(diào)用了一次,是因?yàn)槟?code>$interval的回調(diào)函數(shù)fn
here takes too little time.