angularJs 页面定时刷新


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(); });
复制代码
.state('test', {

      url: '/test',

     cache:'false',

     templateUrl: 'templates/test.html',
      controller: 'testCtrl'
    })
$state.go("xxx", {}, { reload: true });

  .state('test', {
      url: '/test',
      templateUrl: 'templates/test.html',
      controller: 'testCtrl'
    })
.controller('testCtrl', function($scope,$state,$window) {
    $scope.loadData= function() {
            alert(123);
    }
    $scope.loadData();
})
3、
AngularJs 刷新页面可采用下面的方式:首先先在控制器中注册$window,然后定义函数$scope.reloadRoute,在需要刷新页面的地方调用函数$scope.reloadRoute即可。
$scope.reloadRoute = function () {
    $window.location.reload();

};

 

上面是我在项目开发中用到的刷新页面的常用方式,以后用到了其他刷新页面的方式,再总结于此。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM