Reputation: 11234
I need to make a simple animation for quick pick to lotto line with $interval. The problem is that the interval never clear and i dont know why.
This is the important part of the code:
$scope.quickPick = function() {
var count = 0;
var lineAnimation = $interval(quickPickInterval, 200);
function quickPickInterval() {
$scope.clearLot();
$scope.line.nums = _.sample(_.range(1, guessRange + 1), 5);
_($scope.line.nums).forEach(function(num) {
num = _.find($scope.cells, {
num: num
});
num.isSelected = true;
});
++counter;
if(counter == 3) {
$interval.cancel(lineAnimation);
}
}
}
and this is the plunker: http://plnkr.co/edit/vWGmSEpinf7wxRUnqyWq?p=preview
Upvotes: 0
Views: 105
Reputation: 48
Fix your code, count
, no counter
//...
++count;
if(count == 3) {
//...
See fixed example, pls http://plnkr.co/edit/qeHmoNGQ3g3mW82c06OU?p=preview
Upvotes: 3