-
Notifications
You must be signed in to change notification settings - Fork 3k
Order of resolves and rendering #459
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
Are you using 0.2.0? #73 |
Yeah, 0.2.0. #73 seems like a different issue. |
Sorry -- I didn't recognize the difference. |
Imagine you have your view setup like this
and then you had two states: |
The order of resolves should be handled in #73, if I understand correctly.] If that's the case then it would seem that whatever is happening in your controllers could be made to happen in the order you're describing. Also, perhaps you could write your controllers so that they don't depend directly on each other but each depend on the resolved values to which they have access. But again, maybe I'm not understanding the issue. |
Just curious -- are you by any chance using "controller as" syntax? |
#73 is about resolve orders (i.e. having both parent and child resolves), which is something I'm not talking about. I only have a single resolve in the child. The problem is that the parent ui-view doesn't render, or instantiate the parent controller until the child resolve has completed. I am using |
So in other words this is what I think should happen: state definitions: $stateProvider.state('parent', { abstract: true, templateUrl: 'parent_template', controller: 'ParentCtrl' })
.state('parent.child', { url: '/child', templateUrl: 'child_template', controller: 'ChildCtrl',
resolve: { someObj: function(myService) { return myService.getObjPromise(); }}}); Now when the app is loaded (/child), the parent_template & ParentCtrl should be loaded before the resolve of the child completes. |
Gotcha. |
Sweet. I think I might have some work arounds, but any ideas would be appreciated. |
The work around I can think of is not to use resolve in your child state and get its data when the controller is instantiated instead. You'd need to do some different stuff with your rendering to get the effect that I assume you're looking for. |
Yeah thanks. That turns out to be exactly what I did. Would be nice in the future though if ui-router did work the way above. |
The currently-implemented phased approach is tied into the lifecycle of state transitioning and view rendering. Breaking it for your special case is really not an option, sorry. Honestly, it sounds like you're trying shoehorn your code into a combination of nested controllers & resolves, and trying to synchronize those in that way is actually a symptom of a deficiency in your design. You're probably much better off extracting the whole thing out into a service that manages your asynchronous data, and can queue incoming operations against it. |
I completely disagree that my case is "special". Others surely have use cases where rendering the parent before a child is required. The only difference here, is that one of the children needs to resolve some data before getting built. With the current ui-router design, you gain practically nothing by allowing child states to resolve, other than being able to use state params. Please, what do you think is more useful?
|
For data i'd pass stateparams to controllers and let them load their data from services. Components are presented as spinner gifs until the promises that are resolved within the controller. You gain flexibility by not using ui-router's resolve to load data. Im glad I have the option to do it eithrr way though and neither seems broken. |
Stu that is what I have ended up doing, and it works fine. The reason why I liked the appeal of using resolve, was because it would enforce dependence for all further possible children. With the way you have described above, any further children need to individually check the resolved state of the data for every controller. |
If you sey up services that graciously lazy load your data for you it can feel pretty clean in the controllers.... theres something about it that feels like "extra work" but it doesn't bother me too much. |
That's true. |
The currently-implemented phased approach means that something will be displayed only when full view's hierarchy will be resolved. Did I understand that correctly?
Is that principal position? Or it could be changed to |
I have a situation where I have a parent state which is like a toolbar/frame, and a child state which contains some content, however the content requires a resolve to complete. I thought ui-router would elegantly load the parent controller before needing to complete the child resolve.
In other words, the app currently goes: child_resolve->parent_ctrl/view->child_ctrl/view, when I believe it should go: parent_ctrl/view->child_resolve->child_ctrl/view. Is there any reason why it doesn't occur in this fashion? Any possible work around?
The text was updated successfully, but these errors were encountered: