Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload or re-render the entire page using AngularJS

After rendering the entire page based on several user contexts and having made several $http requests, I want the user to be able to switch contexts and re-render everything again (resending all $http requests, etc). If I just redirect the user somewhere else, things work properly:

$scope.on_impersonate_success = function(response) {   //$window.location.reload(); // This cancels any current request   $location.path('/'); // This works as expected, if path != current_path };  $scope.impersonate = function(username) {   return auth.impersonate(username)     .then($scope.on_impersonate_success, $scope.on_auth_failed); }; 

If I use $window.location.reload(), then some of the $http requests on auth.impersonate(username) that are waiting for a response get cancelled, so I can't use that. Also, the hack $location.path($location.path()) doesn't work either (nothing happens).

Is there another way to re-render the page without manually issuing all requests again?

like image 583
andersonvom Avatar asked May 22 '13 23:05

andersonvom


People also ask

How can I refresh a page in angular?

Use window. location. reload() to Reload Current Page in Angular.

How do you refresh a page without losing data?

The easiest way to reload the current page without losing form data, use WebStorage where you have -persistent storage (localStorage) or session-based (sessionStorage) which remains in memory until your web browser is closed.


1 Answers

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.

like image 180
andersonvom Avatar answered Sep 24 '22 23:09

andersonvom