Maintaining selected mat-tab state across Angular components without using localStorage or service
Question: I'm working on an Angular application where I have multiple components containing mat-tab-group. I want to preserve the selected tab state when navigating between these components. I've already implemented a solution using local Storage and a service, but I'm looking for an alternative method that doesn't involve these approaches.
Here's the specific behavior I'm trying to achieve:
Select a tab in Component A. Navigate to Component B. Return to Component A, and the previously selected tab should remain selected instead of defaulting to the first tab. I've tried to to manage it with flag(true , false) but it still defaults to the first tab. How can I achieve this without using localStorage or a service? Any suggestions or code examples would be greatly appreciated.
Angular How to catch mat-tab changed event
You can do it with
MatTabChangeEvent. I think I understood something similar. Can you please check it?