<a ng-href="#" class="navbar-brand" title="home" data-translate>PORTAL_NAME</a>
我想重新加载页面。我该怎么做呢?
发布于 2014-02-19 23:55:13
您可以使用$route
服务的reload
方法。在控制器中注入$route
,然后在$scope
上创建一个reloadRoute
方法。
$scope.reloadRoute = function() {
$route.reload();
}
然后你可以像这样在链接上使用它:
<a ng-click="reloadRoute()" class="navbar-brand" title="home" data-translate>PORTAL_NAME</a>
此方法将导致当前路由重新加载。但是,如果您想要执行完全刷新,则可以注入$window
并使用:
$scope.reloadRoute = function() {
$window.location.reload();
}
**稍后编辑(ui-router):**
正如JamesEddyEdwards和Dunc在他们的答案中提到的,如果您使用angular-ui/ui-router,您可以使用以下方法重新加载当前状态/路由。只需注入$state
而不是$route
,然后您就拥有了:
$scope.reloadRoute = function() {
$state.reload();
};
发布于 2014-02-19 23:59:25
window
对象是通过easier testing and mocking的$window
服务提供的,您可以使用以下内容:
$scope.reloadPage = function(){$window.location.reload();}
和:
<a ng-click="reloadPage" class="navbar-brand" title="home" data-translate>PORTAL_NAME</a>
顺便说一句,我认为$route.reload()实际上并没有重新加载页面,而是only the route。
发布于 2015-08-27 20:14:04
location.reload();
真的很管用。
<a ng-click="reload()">
$scope.reload = function()
{
location.reload();
}
不需要路由或任何东西,只需要简单的老式js
https://stackoverflow.com/questions/21885518
复制相似问题