I want to be able to communicate (i.e. call methods) between a component instance and one of its child component instances. Or just as good for me, call from one component instance to the parent component instance.
For example, take this pseudo setup:
@Component({
selector: 'outerC',
template: `
<div>stuff</div>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{path:'/', name: 'ItemList', component: ItemListComponent, useAsDefault: true},
{path:'/:id', name: 'ItemDetail', component: ItemDetailComponent},
])
export class OuterComponent
{
constructor( ) { }
}
@Component({
selector: 'item-list',
template: `<div>stuff</div>`
})
export class ItemListComponent
{
constructor( ) { }
something() { return x; }
}
@Component({
selector: 'item-detail',
template: `<div>stuff</div>`
})
export class ItemDetailComponent
{
constructor( ) { }
something() { return x; }
}
I'd like the code in OuterComponent to be able to call the something() method on whichever component instance that the router inserts at the router-outlet location. Or, conversely and more generally, I'd like code in ItemListComponent or ItemDetailComponent to be able to call methods on the OuterComponent instance that is hosting them.
Is there a "right" way for these instances to get references to each other? It doesn't look like there's an interface on Router to let OuterComponent find out what the Router has inserted at the router-outlet.
I've looked at the ViewQuery stuff and I can sorta make it work. But it requires that I code specifically for the class names that I'm looking for. As my RouteConfig evolves and gets lengthy, I dislike the idea that I'd have to manually keep a parallel list of the possible components in my Query.
Any ideas, or feedback about why I'm looking at this the wrong way?
Thanks!