MatTabNav Docs show a method that can be used to update the active links for a mat-tab-nav. No examples of how to implement this seem to exist and the source code does not give any better insight into how to implement.
Here is the html from my template:
<nav mat-tab-nav-bar #tabs>
<a mat-tab-link *ngFor="let link of links"
(click)="activelink = link.identifier"
[active]="activelink === link.identifier"
[routerLink]="[ './', link.identifier ]"
>{{ link.title }}</a>
</nav>
I have attempted to access the method using the following two examples, however neither one seems to allow me to access the updateActiveLink method on this.tabs.
Failed attempt 1
@ViewChild( 'tabs' ) tabs: MatTabNav;
And failed attempt 2
@ViewChild( 'MatTabNav' ) tabs: MatTabNav;
What is confusing is that it it shows I need to pass a reference to the element to the item this.something.updateActiveLink( this.tabs ) so I attempted to import MatTabNav in the custructor and access it like so _matTabNav.updateActiveLink( this.tabs )
constructor(
private _matTabNav: MatTabNav,
) { }
My End goal
I intend to highlight the first of the links when the route does not contain my tab. Also when the route is changed, I would like the tabs to reflect this change. So the first line will end up selecting the same
/route/
/route/tab1
/route/tab2
/route/tab3
And my routes which are both routing to the same component
{ component: MyTabComponent, path: 'route/' },
{ component: MyTabComponent, path: 'route/:tab' },