如何使用 Angularjs 使用超时重新加载视图?

How to reload a view using Angularjs using a timeout?

我正在构建一个简单的仪表板,其中有多个视图。 我想设置一个刷新时间 - 大约 60 秒 - 以自动刷新用户选择的视图。

这是我的 Angular 应用的一个区块:

var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
    $routeProvider
    .when("/", {
        templateUrl : "dashHome.html"
    })
    .when("/OverallView", {
        templateUrl : "dashOverallView.html"
    })
    .when("/DetailedView", {
        templateUrl : "dashDetailedView.html"
    })
    .when("/GraphicView", {
        templateUrl : "dashGraphicView.html"
    })
    .otherwise({
        templateUrl : "dashHome.html"
    });
});

所以,假设用户在 OverallView 上。我想每 60 秒刷新一次此视图,而不重新加载所有页面。只是风景。

我该怎么做?

使用$route.reload();

AngularJS documentation:

Causes $route service to reload the current route even if $location hasn't changed.

As a result of that, ngView creates new scope, reinstantiates the controller.

在 $timeout

内在您的控制器上调用它