I need to listen for an event from an array of tab components. These tabs emit "onMinimized" however I would rather hook up to these events in one line of code than entering (onMinimized)="hide"
for each tab component entry in the template. There is an array of ContentChildren that I have which I can loop through.
I want to do something similar to has follows in the parent:
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
...
ngAfterContentInit() {
this.tabs.map((t: TabComponent) => {
t.addEventListener("onMinimized", this.hide);
});
}
hide() {
// hide tabs
}
Thoughts?
Figured it out after some trial and error.
ngAfterContentInit() {
this.tabs.map((t: TabComponent) => {
t.minimizeTab.subscribe(() => { this.hide(); })
});
}
The way to approach the problem was to consider that the component had a property which was an EventEmitter (just like all angular Outputs). EventEmitters are observables, so you can simply subscribe to the stream of events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With