How to reload or re-render the entire page using AngularJS
For reloading the page for a given route path :-
$location.path('/path1/path2');
$route.reload();
For the record, to force angular to re-render the current page, you can use:
$route.reload();
According to 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.
$route.reload()
will reinitialise the controllers but not the services. If you want to reset the whole state of your application you can use:
$window.location.reload();
This is a standard DOM method which you can access injecting the $window service.
If you want to be sure to reload the page from the server, for example when you are using Django or another web framework and you want a fresh server side render, pass true
as a parameter to reload
, as explained in the docs. Since that requires interaction with the server, it will be slower so do it only if necessary
Angular 2
The above applies to Angular 1. I am not using Angular 2, looks like the services are different there, there is Router
, Location
, and the DOCUMENT
. I did not test different behaviors there
If you are using angular ui-router this will be the best solution.
$scope.myLoadingFunction = function() {
$state.reload();
};