How to stop $interval on leaving ui-state?

后端 未结 1 495
梦如初夏
梦如初夏 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)
提交回复
热议问题