-
Notifications
You must be signed in to change notification settings - Fork 3k
Parent resolve values are not overridden by children #868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
+1 |
I'm not opposed to this and I do think that it waits for all the state heirarchy resolves to be ready before instantiating any controllers. So refreshing on '/a' I could see setting $scope.selected to the child value, but what if you are in '/' and then navigate to '/a'? Then the parent controller was already instantiated on the first page and would not be re-instantiated on the second. Is this acceptable behavior? |
Absolutely. In this case, it's the parent controller navigating from '/' to '/a' and passing in the selected param so the parent and child state would still be in sync. In the case where the connection is less direct, I believe an instantiated parent controller would be able to listen for a state change event and access the resolved child values through that mechanism. If I really wanted the parent to be re-instantiated I'd expect to have to pass 'reload' to the transition. |
Would you want to do a pull request? :) |
@timkindberg I will start researching this to add it if it's still something you'd accept a PR for, but if it's no longer of interest I will look for another way to do what I am trying to do. Are you still interested in having someone try to solve this problem? |
The documentation clearly says:
So I assumed that child state can overwrite/neglect parent`s resolver. But it is not. |
+1 |
I'm with @goliney in my assumptions. Had hoped i could override the parent's resolver in the child so that the parent's is ignored. |
+1 |
+1 |
+1 to this problem |
Is this something being worked on? Because I've hit this problem aswell. Are there any alternatives that disable the parents resolve in the childs? |
The example pluker is not so useful in most cases . A common usable case when using child state(s), will be using the same controller instance as well as the same root template (while using some new view(s) - hence the views option.). Here is a hacky solution to the problem: |
I'm not sure if it's related or not but here is a plunk inspired by @TomerAvni hacky solution where I need to have different controllers according to $state params while keeping the parent/child relation for my breadcrumb & active tab. Here is a plunk: http://plnkr.co/edit/jieVD94XLzufBw8JKUHW?p=preview |
+1 when using the same parent controller |
@TomerAvni, not working with promises... |
Just ran into this issue today. Any updates on if it will be fixed or any workarounds? |
This is not broken; it works as designed. Resolves are hierarchical. You can override parent resolves in a child, but the override is only applicable to the child (and its children). It does not retroactively modify resolves in the parent state/views. |
@christopherthielen Can you elaborate? It seems to me that the plunk by @TomerAvni demonstrates the opposite behavior. |
Actually, ksperling's comment in #78 helped me.
|
This is still an issue, its not updating the resolve values using promises and one parent controller |
This is not broken; it works as designed. Resolves are hierarchical. You can override parent resolves in a child, but the override is only applicable to the child (and its children). It does not retroactively modify resolves in the parent state/views. |
@christopherthielen I am not talking about the resolve value changing the parent state, I mean the value does not change in the children states even when you go child right away, Here is a plunker with an example of what I am talking about |
Thanks for the plunker. I'll take a look!
|
@sam-soltech views are rendered in their own state's context. So your parent view always renders the parent resolve value. If you create a child view, it renders the child resolve which has the overridden value |
Has same issue.
My controller function
|
I also just realized I was being hit by this behaviour. I had two states that used an identical state definition aside from the resolves, so I thought I could refactor them into parent/child, with the child only specifying a different set of resolves, so as to avoid code duplication. What I am understanding from this discussion is that that is not actually possible, is that correct? In my case, both the parent and child resolves were being run, but the parent resolve is what was being injected into the controller. What I'm after is the ability to override the resolve entirely, so the parent resolve is never even run. Is this not possible somehow? |
Well, I just created child state, added to its config resolver with same name as parent state has, and parent resolver is still running (along with child's one). What am I doing wrong? |
Here is a workaround for promises based off @TomerAvni solution: http://plnkr.co/edit/xGdRlobk0yHQi9r2iUrP?p=preview |
@lexigren you're not doing anything wrong, maybe just misunderstanding. Let's say you have two states: Both If you inject |
Child states can override a parent's data values, but they cannot override a parent's resolve values. In the code below, when refreshing on "/" parentData is 'parent' and selected is null. When refreshing on "/a" parentData becomes 'child' but selected remains null. Obviously the parent controller needs to manage it's internal state and scope during state transitions but on initial load it feels as though child resolved values should take precedence as data does.
Is this a bug or by design?
It would be nice if resolves behaved in the same way as data. Being able to inject resolved values instead of querying $state.params and resolving within the controller has a number of benefits.
The text was updated successfully, but these errors were encountered: