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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM