简体   繁体   English

angularjs重新加载页面,但设置新的URL

[英]angularjs reload page but setting new URL

Hi im trying to use $window.location.reload() but i need to use a new URL so this URL have the routeParams that a service use. 嗨,我尝试使用$window.location.reload()但我需要使用新的URL,以便此URL具有服务使用的routeParams

here is my piece of code: 这是我的代码:

 $window.location.href += "/" + $scope.var1 + "/" + $scope.var2;
 $window.location.reload(true);

the thing with this approach is that the url change but when reload it set it to the default route of my app taking out the href i set. 这种方法的作用是更改url,但在重新加载时将其设置为我的应用程序的默认路由,而不使用我设置的href。

it is a good practice to always use angular services, try to never use window or jquery functions, angular provides them all, in this case i think you should try with the $location service 这是一个很好的做法,始终使用角度服务,尝试从来不使用窗口或jQuery的功能,角度为他们提供一切,在这种情况下,我认为你应该用尽量$location服务

https://docs.angularjs.org/api/ng/service/ $location https://docs.angularjs.org/api/ng/service/ $ location

$location.path('your url')

if all you need is reload the current path better use the $route service 如果您需要的只是重新加载当前路径,最好使用$route服务

$route.reload();

this will only reload your ngView, if you need to reload all the page 这样只会重新加载您ngView,如果你需要重装所有页面

$window.location.reload();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM