in angular mat how can i get previously selected mat-tab in component even after exploring other components ? without using localstorage and service?

51 views Asked by At

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.

1

There are 1 answers

2
Ali Bektash On

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?