How can I stop an AngularJS $interval? -
i have code inside function gets called every 1 or 2 minutes. counts down 60 0 (i've set 60 maximum number of iterations).
var timer = $interval( function (times: number) { var retry = 60 - times; $scope.retrymessage = "retry + " seconds"; }, 1000, 60);
from can see documentation suggesting $interval must cancelled when can this? assume cannot add:
$interval.cancel(timer);
after code.
$interval returns promise. can cancel this
var times = 60; var promise = $interval( function () { var retry = 60 - (times++); $scope.retrymessage = retry + " seconds"; if(retry == 30){ //cancel in 30 seconds instead .. reason $interval.cancel(promise); } }, 1000, 60);
Comments
Post a Comment