如何重新加载或使用AngularJS重新渲染整个页面

编程入门 行业动态 更新时间:2024-10-26 22:29:54
本文介绍了如何重新加载或使用AngularJS重新渲染整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

呈现整个页面基于几个用户上下文和已经提出了若干 $ 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重新渲染整个页面

本文发布于:2023-10-12 20:59:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485880.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   页面   AngularJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!