AngularJs:重新加载页面 [英] AngularJs: Reload page
问题描述
<a ng-href="#" class="navbar-brand" title="home" data-translate>PORTAL_NAME</a>
我想重新加载页面.我该怎么做?
I want to reload the page. How can I do this?
推荐答案
您可以使用 $route
服务的 reload
方法.在您的控制器中注入 $route
,然后在您的 $scope
上创建一个方法 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>
此方法将导致当前路由重新加载.但是,如果您想执行完全刷新,则可以注入 $window
并使用它:
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-router):**
正如 JamesEddyEdwards 和 Dunc 在他们的回答中提到的,如果您使用的是 angular-ui/ui-router 您可以使用以下方法重新加载当前状态/路由.只需注入 $state
而不是 $route
然后你有:
**Later edit (ui-router):**
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屋!