呈现整个页面基于几个用户上下文和已经提出了若干 $ HTTP 请求之后,我希望用户能够切换上下文并重新渲染一切(重发均 $ HTTP 的要求,等等)。如果我只是将用户重定向别的地方,事情正常工作:
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); };如果我用 $ window.location.reload(),那么一些关于 $ HTTP 请求 auth.impersonate(用户名)正在等待回应被取消,所以我不能使用它。此外,黑客 $ location.path($ location.path())不工作,要么(什么也没有发生)。
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?
推荐答案有关记录,以迫使角度重新呈现当前页面,你可以使用:
For the record, to force angular to re-render the current page, you can use:
$route.reload();据AngularJS 文档:
$原因航线的重新加载当前路由即使在$位置没有改变。
Causes $route service to reload the current route even if $location hasn't changed.
由于该结果,ngView创建新范围,重新实例控制器。
As a result of that, ngView creates new scope, reinstantiates the controller.
更多推荐
如何重新加载或使用AngularJS重新渲染整个页面
发布评论