Reputation: 151
I'm working with angular.
I have a problem with a $timeout function. it is initiate on ng-mousedown so if I clic 2 time, it set 2 timer. That I want to avoid. How Can I delete previous timer to keep only the last one? Here the code:
$scope.stopRefresh = function() { //ng-mousedown
$interval.cancel(autoRefresh);
restartRefresh = $timeout(function(){
startRefresh();
},30000);
};
Upvotes: 0
Views: 652
Reputation: 3240
This code should work:
$scope.stopRefresh = function() { //ng-mousedown
$interval.cancel(autoRefresh); //I am not clear with the purpose of this line.
if(restartRefresh){
$timeout.cancel(restartRefresh);
}
restartRefresh = $timeout(function(){
startRefresh();
},30000);
};
Upvotes: 2