在浏览器中更改URL参数时刷新角度页面 [英] Angular page refresh on changing URL parameter in browser
本文介绍了在浏览器中更改URL参数时刷新角度页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
非常简单的要求,但是很难.有一个简单的页面,我可以在其中在网址路径中打印参数.
Extremely simple requirement but having a hard time with this. Have simple page where I print the parameter in the url path.
http://localhost:8888/ngtest.html#/1234567
ngtest.html
<div ng-app="app" ng-controller="testCtrl">
{{myId}}
</div>
<script>
var app = angular.module('app', []);
app.controller('testCtrl', function($scope, $location) {
$scope.myId = $location.$$path;
});
</script>
在浏览器窗口中:
- 将
1234567
更改为1234
- 点击Enter
什么都没发生.按F5键,即可正常使用.
Nothing happens. Hit F5 and it works as expected.
不确定这是否与浏览器行为有关,但是如何在参数更改+ Enter之后如何强制页面刷新?
Not sure if this has something to do with browser behavior but how to force the page to refresh after parameter change + Enter?
推荐答案
页面刷新已得到回答您可以使用 $ route.reload();
按照建议的此处,您可以尝试在按Enter键时侦听路由更改是否成功在网址输入中:
As suggested here, you can try listening for route change success when hitting Enter in the url input:
scope.$ on('$ routeChangeSuccess')
或 scope.$ on('$ locationChangeSuccess').
这篇关于在浏览器中更改URL参数时刷新角度页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文