使用$ state.go()时,ui-router不会运行父状态的可解决承诺 [英] ui-router does not run a parent state's resolve promise when using $state.go()

查看:125
本文介绍了使用$ state.go()时,ui-router不会运行父状态的可解决承诺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有可解决承诺的抽象父状态,该状态返回有关当前用户的信息.此信息被注入到所有子状态的控制器中.

I have an abstract parent state with a resolve promise which returns information about the current user. This information is injected into controllers of all the child states.

但是,当我使用$state.go('parent.child')时,未执行resolve promise函数.但是,如果我浏览到表示该状态的URL,它将很好地执行.

However when I use $state.go('parent.child') the resolve promise function is not being executed. If I browse to the URL representing that state though, it executes fine.

我是否需要在每个子状态下指定resolve对象,并从父级状态中忽略它?

Do I need to specify the resolve object on each child state and omit it from the parent?

推荐答案

对于给定的一组$stateParams值,父状态解析将只解析一次.如果父状态不依赖$stateParams或不使用$stateParams,则无论子状态有何变化,其依赖项都将仅被解析一次.

A parent state resolve will only resolve once for a given set of $stateParams values. If the parent state does not rely on $stateParams or does not use any, then its dependencies will only be resolved once, regardless of any child state changes.

您看到的行为差异是子状态更改不会导致重新加载父资源,而位置更改将重新加载完整的父状态和子状态.

The difference in behaviour you are seeing is a child state change will not result in the parent resources being reloaded, whereas the location change will as the full parent and child states are reloaded.

您可以在此 plunk 中观察到这种行为.

You can observe this behaviour in this plunk.

该示例在子代所依赖的父状态下具有$stateParams值.通过$state.goui-sref(提供这两种方法)更改状态将导致刷新父资源.但是,将状态更改为子状态而不更改$stateParams参数将不会刷新父资源,并且将提供以前返回的值.

The example has a $stateParams value in the parent state on which the children are dependent. Changing state via $state.go or ui-sref (both methods are provided) will result in a refresh of the parent resource. However, changing state to a child state without a change to the $stateParams parameter will not refresh the parent resource and the previously returned value will be provided.

这篇关于使用$ state.go()时,ui-router不会运行父状态的可解决承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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