How to stop $interval on leaving ui-state?

后端 未结 1 502
梦如初夏
梦如初夏 2021-02-19 16:40

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 16:56

    clear interval on $destroy

    Like this

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