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?
I've had a hard fight with this problem for months, and the only solution that worked for me is this:
For reloading the page for a given route path :-
If you are using angular ui-router this will be the best solution.
Well maybe you forgot to add "$route" when declaring the dependencies of your Controller:
Easiest solution I figured was,
add '/' to the route that want to be reloaded every time when coming back.
eg:
instead of the following
use,
For the record, to force angular to re-render the current page, you can use:
According to AngularJS documentation: