首页 > 解决方案 > 我想每 60 秒刷新或重新加载 $scope

问题描述

Hi I am learning angularjs.
The main idea is to "refesh" or "reload" the $scope.
I was able to refresh the page with this ```location.reload();````.
But i was recomended to refresh the $scope, not the hole page.
I reserached about this, I reckon I should use apply or digest.
As so far the code is like this:

刷新.component.js

    myApp.component('refreshComponent', {
        template:"<button class='btn btn-lg btn-info text-uppercase' ng-click='vm.refresh()'Refresh </button>",
        controllerAs: 'vm',
        controller: function RefreshController($scope, $element, $attrs) {
           vm = this;

          vm.refresh = function(){
            location.reload();
          }
        }
      });

据我了解,这应该改变:(这是假设,我不知道,如果我应该保留组件或重构为控制器或其他东西,我不清楚)

  1. 该按钮不应再存在,因此它将每 60 秒自动刷新一次。
  2. 该组件不应再存在。
  3. 我有一个 utils.js,我想我应该在其中放置下一个代码:
    setTimeout($scope.apply(), 60000);
    setTimeout($scope.digest(), 60000);
    

我不知道,如果我以正确的方式使用 apply 或 diggest

标签: angularjshashtimeoutrefreshapply

解决方案


推荐阅读