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?
Use window. location. reload() to Reload Current Page in Angular.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With