How to stop $interval on leaving ui-state?

后端 未结 1 1488
忘了有多久
忘了有多久 2021-02-19 16:21

Angular, UI-router. Using $interval in a controller of a state like so:

$scope.Timer = null;

$scope.startTimer = function () { 
    $scope.Timer = $interval($sc         


        
相关标签:
1条回答
  • 2021-02-19 17:11

    clear interval on $destroy

    Like this

    $scope.$on("$destroy",function(){
        if (angular.isDefined($scope.Timer)) {
            $interval.cancel($scope.Timer);
        }
    });
    
    0 讨论(0)
提交回复
热议问题