I have a sidebar component and a page component.
The sidebar component has a @ViewChild
which is an ngbAccordion
from Angular Boostrap. I want to trigger its collapseAll
method from the page component.
So the sidebar has
@ViewChild('webAccordion', { static: false })
webAccordion: NgbAccordion;
@ViewChild('pageAccordion', { static: false })
pageAccordion: NgbAccordion;
collapseAllAccordions() {
this.webAccordion.collapseAll();
this.pageAccordion.collapseAll();
}
When the "page" component loads, I want to emit an event to the "sidebar" component that triggers my collapseAllAccordions
function.
I know how to do this with parent/child components, and most of the stuff I can find with Google and here on SO discusses parent/child situations. Except in my case they are sibling components. I'm not sure how to hand siblings.
You can use a service:
collapseAllAccordions
.