I'm building a simple dashboard, where I have multiple views. I would like to set a refresh time - around 60 seconds - to automatically refresh the view the user has selected.
Here is a block of my Angular app:
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"
});
});
So, let's say, the user is on the OverallView. I would like to refresh this view every 60 seconds, without reloading all page. Just the view.
How can I do that?
Use $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.
Call it on your controller within a $timeout