AngularJs:刷新页面 [英] AngularJs: Reload page
问题描述
<a ng-href="#" class="navbar-brand" title="home" data-translate>PORTAL_NAME</a>
我想重装page.How可以添加这样做呢?
I want to reload a page.How can add to do this?
推荐答案
您可以使用 $路线的
服务。注重新加载
法 $路线
在您的控制器,然后创建你的 $范围的方法
。 reloadRoute
You can use the reload
method of the $route
service. Inject $route
in your controller and then create a method reloadRoute
on your $scope
.
$scope.reloadRoute = function() {
$route.reload();
}
然后你可以使用它像这样的链接:
Then you can use it on the link like this:
<a ng-click="reloadRoute()" class="navbar-brand" title="home" data-translate>PORTAL_NAME</a>
此方法将导致当前路由重新加载。不过,若你要执行完全刷新,你可以注入 $窗口
并使用:
This method will cause the current route to reload. If you however want to perform a full refresh, you could inject $window
and use that:
$scope.reloadRoute = function() {
$window.location.reload();
}
结果
后来编辑(UI路由器):
结果
在他们的答案中提到由JamesEddyEdwards和Dunc,如果您正在使用角-ui / UI路由器你可以用下面的方法来重新加载当前状态/路由。刚刚注入 $状态
而不是 $路线
,然后你必须:
As mentioned by JamesEddyEdwards and Dunc in their answers, if you are using angular-ui/ui-router you can use the following method to reload the current state / route. Just inject $state
instead of $route
and then you have:
$scope.reloadRoute = function() {
$state.reload();
};
这篇关于AngularJs:刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!