-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Nested components with Angular 1.5 and latest ui-router version #2896
Comments
We don't currently support binding attributes from the parent component, through the ui-view, to the child routed component. This idea is something that a few people have raised. I've given it some thought, but don't know if it is a reasonable idea for ui-router architecture, or if it introduces too tight of parent/child coupling. However, your current options for jumping the logical ui-view boundary are:
#1 is tightly coupling the child component to the parent. |
@christopherthielen not sure if this is a valid use case that would help you to further consider this, but I have wanted to do something like the following in my app. Consider a set of pages that are for managing a user's account. The base URL might be The "parent" in this case might be a component named the
Every tab-page is a child of this parent state, but needs access to the
And the route definitions that don't work atm:
As far as your comment goes that adding this functionality might introduce too tight a coupling, based on my example I can't see this being a problem - the inputs and outputs of each component are still just as clear. The child just says "hey, I need a With regards to your proposed alternatives, if this feature is not something that will ever happen I'd love to see some examples of how you might do 1. or 2. above as it's not immediately clear to me. Some thoughts I've had on them:
Anyway, would be great to hear your thoughts, and thanks for your time. Jon. |
I'm having tons of trouble passing callbacks due to no native functionality in ui-router also. I would expect that I could pass callbacks from the parent to child state just like a component. Is there something I'm missing? It seems too complicated and hard to pass data/functions from parent to child. EDIT: I found a solution here and it works great. |
I'm becoming more open to allowing attribute bindings to pass through a ui-view down to the routed component. e.g.:
where on-change binding is passed through to the route-to-component template, like I don't have time to work on this now, but would be happy to work with anyone attempting a PR. I suspect it's not as simple as it seems at first glance, but I think it's possible. |
cc: @fpipita @lucianogreiner @timothyswt @michalpanek |
How do you do this? "expose a container object as a resolve in the parent state. Update a property in the parent component, and bind the resolve to the child (reading the data off the property)." Any simple code example or docs? Thanks! |
Oh is this what you mean?
|
When I look at this, something smells wrong with being able to basically inject parameters from the ui-view usage down to components. This would open up the possibility to some really bad practices and sort of "side-injecting" things in a weird way. It seems to me that the route declaration should be solely responsible for providing models and events to the component being rendered. I think it would be nice to have say, higher-order components which simply abstract reusable functionality, but angular 1x doesn't technically support that. What we are doing to compensate is to render a component which...renders another component... the grossness is in the dom where extraneous html tags end up being created which can complicate the CSS a little, but we haven't really found a better way yet. |
@jmanuelrosa see af95206 @shawnlan yes, that's what i meant about resolving a container to be modified by the child state @timothyswt I'm all ears about better way to approach this. Originally, I had a very similar opinion to yours and thought that the components shouldn't communicate beyond a ui-view boundary. However, my views have since changed. There's the line of thought that changed my view: I am writing an app that is component driven. Data is passed down from parent to the (dumb component) child and events are fired by the child and handled by the parent component. Now I want to make the child component routable. Why then should I be forced to adopt a completely different paradigm simply because it's routed? The child component is still a dumb component. It still receives input via input bindings and emits events via output bindings. This change allows the parent component (the smart component) to handle events from the child component as before, without demanding any shift in my component based approach.
I used to have the same opinion. However, I've since broadened my views to accommodate developers who prefer the smart component to handle those concerns. In many cases, the STATE itself (as opposed to component) may indeed be able to "act as the smart component" by providing the proper callbacks (as we've discussed in #3111 (comment)) doing logic like saving data, then reloading states. Sometimes, though, manipulating the state machine might not be sufficient. You might need to access some component state (in the parent/smart component) to determine the right behavior.
Can you expand on this concern? I'd like to hear more arguments.
Of course, that's still your prerogative. As I'm sure you're aware, UI-Router tries to be flexible, and as part of that flexibility, I'm trying to accommodate the component model folks who want to make their component tree routable. I'm closing this issue because the original reported scenario is now in rc.1. I'd like to continue the discussion, however, so feel free to tell me why I'm wrong 😉 |
Since this has been added recently, where can I find official documentation or examples on how to use this feature in rc1? Thanks! |
https://ui-router.github.io/guide/ng1/route-to-component#routed-parentchild-component-communication |
Thanks! :) |
Hi! I'm trying to use the new 1.5 router and angular components kissing routes, but I arises a problem with nested components
custom
Component has this template:custom
Component:customSon
is this:When I go to
/custom/children
, I can not get the value ofcustomChildrenAttr
. How I can get thecustomChildrenAttr
binding? I try with resolve and other things but I don't get it to work .The text was updated successfully, but these errors were encountered: