Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upRouter - Proposal for creating bindings #5875
Comments
|
An alternative solution would be to provide an optional host template on the route configuration objects. @Component({
selector: 'child'
template: `
<h2>Child</h2>
<p>Param: {{param}}</p>
<button (click)="event.next(this)">Event</button>
`
})
export class Child {
@Input param;
@Output event = new EventEmitter();
}
@Component({
selector: 'app'
template: `
<h1>App</h1>
<a *ngFor="#child of children" [routerLink]="['/Child/' + child.id]">Child {{child.id}}</a>
<router-outlet></router-outlet>
`,
directives: [Child, RouterOutlet, RouterLink, NgFor]
})
@RouteConfig([
{path: '/child/:id', name: 'Child', component: Child, hostTemplate: `
<child [param]="getChild(routeInstruction.params.get('id'))"
(event)="onEvent($event)">
</child>
`}
])
export class App {
children: [
{id: 1, param: 'Param 1'},
{id: 2, param: 'Param 2'},
{id: 3, param: 'Param 3'}
]
getChild(id) {
return this.children.find((child) => child.id === id);
}
onEvent() {
}
} |
|
When I learned about Input and output parameters I was happy as it allowed creating losely-coupled components. Then I started to see if it would be possible to use a component with input/output params with the router. Unfortunately it's not possible. This basically means that input/output params work only if used within the same route, which is not nice. In other words, a component with input/ output parameters has limited reusability. I also vote for an addition of something that would allow to configure component's input/output params in the @RouteConfig annotation. |
|
Lack of
Totally agree. There shouldn't be much difference, maybe except I believe that current Router tries too much rule the component world. It creates components, destroys them and navigate. I believe that Router should only navigate.
Sounds like fixing what we got but I'm sure that's a minimum. @btford I've read that you're responsible for Router, could you refer to this topic somehow? Are there any plans about |
|
To access child component created by router and subscribe to child's events I use this for now:
where |
|
obsolete releates to the former router |
|
I just came to the same conclusion as @gionkunz and was wondering if this was a solved problem? I'm looking for a solution for AngularJS specifically as I'm not on Angular. If it has been solved with Angular though, I'd be interested in how it works (if there's a link with information). As best I can tell with the new 1.0 An example of what I'm looking to do, but with routing TIA! |
|
@langdonx It's way off topic for this issue, but here you go: https://ui-router.github.io/guide/ng1/route-to-component#routed-parentchild-component-communication |
|
@christopherthielen Thanks so much for the prompt reply! I apparently failed to see the "Routed parent/child component communication" section when I last perused. Events on |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The router is great but also comes with a very imperative way of handling things. It's sometimes very hard to leverage the full potential of a component based UI approach when using a router. With my current understanding of the Angular2 router I came to the conclusion that the current design has the following implications:
I wanted to open this issue as a discussion starting point because maybe other people feel the same.
I also came up with a very naive example of how this problem could be solved. It uses a directive that will configure routes from the template and uses templates to activate components that can now be configured declaratively within the view. Additionally the syntax in the binding of the directive allows to extract the resultingComponentInstructionon activation.See second comment for updated proposal
What do you think? @btford @mhevery
Cheers
Gion