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.
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.
Do I need to specify the resolve object on each child state and omit it from the parent?
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.
You can observe this behaviour in this plunk.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With