angularJs 页面定时刷新

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

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();
        });

 

posted @ 2017-02-22 09:37  白洋花海  阅读(2298)  评论(0编辑  收藏  举报