Angular JS - UI-路由器:点击时重新加载状态
Angular JS - UI-Router: Reload state on click
我正在使用 Angular JS 和 UI-路由器,
我想重新加载状态,当我们从相同的状态点击状态 link。
我用下面的代码修复了它,
<a ui-sref="page1" ui-sref-opts="{reload: true}">Page 1</a>
但是在所有link中添加ui-sref-opts="{reload: true}"
是很乏味的。
所以我想要 angular js(或 ui-router)中的配置或设置或代码来全局管理它。也就是说,如果我们从同一状态单击状态 link,则应该重新加载状态。
请帮我找到解决办法。
这里的方法是调整 $state.go
实现,例如像这样:
Changing the default behavior of $state.go() in ui.router to reload by default
通常我们会使用decorator
来控制$state行为
.config(function ($provide) {
$provide.decorator('$state', function ($delegate) {
// let's locally use 'state' name
var state = $delegate;
...
看到 in action here
这里描述了为什么应该起作用:
Difference between ui-sref and $state.go in AngularJS UI-Router
我正在使用 Angular JS 和 UI-路由器,
我想重新加载状态,当我们从相同的状态点击状态 link。
我用下面的代码修复了它,
<a ui-sref="page1" ui-sref-opts="{reload: true}">Page 1</a>
但是在所有link中添加ui-sref-opts="{reload: true}"
是很乏味的。
所以我想要 angular js(或 ui-router)中的配置或设置或代码来全局管理它。也就是说,如果我们从同一状态单击状态 link,则应该重新加载状态。
请帮我找到解决办法。
这里的方法是调整 $state.go
实现,例如像这样:
Changing the default behavior of $state.go() in ui.router to reload by default
通常我们会使用decorator
来控制$state行为
.config(function ($provide) {
$provide.decorator('$state', function ($delegate) {
// let's locally use 'state' name
var state = $delegate;
...
看到 in action here
这里描述了为什么应该起作用: