如何重新加载当前状态

如何重新加载当前状态

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

问题描述

我正在使用 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 并带有传递项目 ID 的 $StateParams.因此,在详细信息状态下,我加载此项目的详细信息,对其进行编辑,然后保存数据.到目前为止一切都很好.

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
});

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

08-20 02:22