Possibility of changing $interval interval on runtime - Angular

时间:2015-07-28 17:02:55

标签: angularjs performance recursion intervals

I need to change the interval value based on user inputs as following:

scope.refreshEvery = 1000;

//run on startup every 1 second
scope.interval = $interval(function () {
    scope.refresh(scope.page);
}.bind(this), refreshEvery);

//onclick will change the interval to 2 seconds 
scope.onclick = function () {
    scope.refreshEvery = 2000;
}

I have seen few solutions for JS setTimeout with recursive but that will not work here specially from a performance aspect as its recommended to cancel all the timeout and interval with the scope destroying event. Is this possible with angular $interval!

0 个答案:

没有答案