Reputation: 13
I have 2 separate component in my Angular application. One of the component is the top navigation bar and it contain the toggle button. Other component is a Dashboard and is in a separate module.
My Dashboard contain 2 div in which either one should be hide/show based on toggle button change in Top Navigation bar component.
example: When toggle toggle button is checked div 1 should be shown and div 2 should be hidden.
Can someone give me a solution with a stack-blitz sample ?
Upvotes: 1
Views: 1491
Reputation: 1931
Remember to use a button (not anchorlink) for toggle
Upvotes: 0
Reputation: 154
Here I assume there is binding across two separate components who are neither a child or parent of each other.
One way this can be handled is:
the Toggle flag can be set and unset with the help of Subject from Rxjs and a service. StackBlitz Link
Upvotes: 1
Reputation: 2623
Angular docs have great examples to handle component interaction
Stackblitz: Link (Assuming your components are neither siblings nor in same module)
Upvotes: 0