Reputation: 13
I have a problem in Angular 2. I have a Main component where I show the menu. This component has a child named Tabs. In this component there are Tab components that are added dynamically when the menu items are clicked in the Main component. I use the @ContentChildren in the Tabs component to get all the Tab components and this works fine. However, to get this to work properly I need to pass these contentchildren further up the the Main component. How would I do this? I have tried emitting, but it doesn't seem to work.
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
@Output() public tabsArrayStart = new EventEmitter();
this.tabsArrayStart.emit(this.tabs);
Upvotes: 0
Views: 316
Reputation: 657268
@Output()
only allows to pass from the parent
(tabsArrayStart)="doSomething($event)
I'd suggest you use a shared service instead.
For more details see https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service
Upvotes: 0