页面定时刷新并在页面离开时停止自动刷新

var autoRefresh;
        //自动刷新
        autoRefresh = $interval($scope.loadData, 60000);
        //停止自动刷新
        $scope.stopAutoRefresh = function () {
            if (autoRefresh) {
                $interval.cancel(autoRefresh);
                autoRefresh = null;
            }
        };

        //切换页面时停止自动刷新
        $scope.$on('$routeChangeStart', function (angularEvent, current, previous) {
            $scope.stopAutoRefresh();
        });

 

相关文章: