【发布时间】:2015-07-30 11:35:54
【问题描述】:
非常简单的要求,但很难做到。有一个简单的页面,我在 url 路径中打印参数。
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 - 回车
什么都没有发生。按 F5 即可按预期工作。
不确定这是否与浏览器行为有关,但如何在参数更改+回车后强制页面刷新?
【问题讨论】:
-
您可能需要为此设置路由功能。见:youtube.com/…
-
为什么还要刷新? SPA 的重点是避免这种情况。
-
如果有效,不刷新肯定没问题。基本上我有像
http://example.com/view.html#/{item_number}这样的入站链接。试图看看它是否可以在没有路由的情况下工作。
标签: javascript angularjs browser