angularjs - 我想每 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();
}
}
});
据我了解,这应该改变:(这是假设,我不知道,如果我应该保留组件或重构为控制器或其他东西,我不清楚)
- 该按钮不应再存在,因此它将每 60 秒自动刷新一次。
- 该组件不应再存在。
- 我有一个 utils.js,我想我应该在其中放置下一个代码:
setTimeout($scope.apply(), 60000); setTimeout($scope.digest(), 60000);
我不知道,如果我以正确的方式使用 apply 或 diggest
解决方案
推荐阅读
- python - 在 Spark Dataframe 中选择一系列列
- ios - AVCaptureDevice 设备为空
- kubernetes - 我如何在 kubernetes 中设置工作人员(基础设施问题)
- powershell - 如何在 PowerShell 中启动多个进程
- python - 使用python代码生成SPSS数据文件的频率时出错
- ruby-on-rails - 如何在 Rails 应用程序中管理大量图像?
- php - PHP - 对嵌套数组执行解析规则
- c# - 二维数组数组边界外的索引
- spring-boot - 如何在不更改其他属性的情况下从 Spring Data 更新 Page 对象内部的内容
- python - 'int' 对象在 for in range 循环中不可调用