如何重新加载当前状态? [英] How to reload the current state?

查看:73
本文介绍了如何重新加载当前状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular UI Router,想重新加载当前状态并刷新所有数据/为当前状态及其父级重新运行控制器.

I'm using Angular UI Router and would like to reload the current state and refresh all data / re-run the controllers for the current state and it's parent.

我有3个状态级别: directory.organisations.details

directory.organisations 包含一个带有组织列表的表.单击表中的项目会加载 directory.organisations.details ,其中$ StateParams会传递该项目的ID.因此,在详细信息状态下,我将加载该项目的详细信息,对其进行编辑,然后保存数据.到目前为止一切都很好.

directory.organisations contains a table with a list of organisations. Clicking on an item in the table loads directory.organisations.details with $StateParams passing the ID of the item. So in the details state I load the details for this item, edit them and then save data. All fine so far.

现在,我需要重新加载此状态并刷新所有数据.

Now I need to reload this state and refresh all the data.

我尝试过:

 $state.transitionTo('directory.organisations');

我想进入父状态但不重新加载控制器,因为路径没有改变.理想情况下,我只想保持 directory.organisations.details 状态并刷新父目录中的所有数据.

Which goes to the parent state but doesn't reload the controller, I guess because the path hasn't changed. Ideally I just want to stay in the directory.organisations.details state and refresh all data in the parent too.

我也尝试过:

$state.reload()

我已经在API WIKI上看到了$ state.reload(错误,现在控制器重新实例化,即将修复)."

I have seen this on the API WIKI for $state.reload "(bug with controllers reinstantiating right now, fixing soon)."

有什么帮助吗?

推荐答案

此解决方案在AngularJS V.1.2.2中有效:

This solution works in AngularJS V.1.2.2:

$state.transitionTo($state.current, $stateParams, {
    reload: true,
    inherit: false,
    notify: true
});

这篇关于如何重新加载当前状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆