zoukankan      html  css  js  c++  java
  • 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();

    };

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

  • 相关阅读:
    HTTP状态码
    CentOS 7 上安装vim(默认未安装)
    yum安装提示Another app is currently holding the yum lock; waiting for it to exit...
    CentOS 7 安装telnet服务
    shell编程
    shell基础
    ssh相关命令
    ssh无密码连接
    centos7小命令
    日志管理
  • 原文地址:https://www.cnblogs.com/sxz2008/p/6603662.html
Copyright © 2011-2022 走看看