Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular material mat-tab-label

I want to access name of the sequence from selectedTabChange event

<mat-tab-group (selectedTabChange)="onSequenceChangeEvent($event, sequence)">

<mat-tab  *ngFor="let sequence of sequencesForSelectedScope">

    <ng-template mat-tab-label>
        <span>{{sequence.sequenceName}}</span>
    </ng-template>

</mat-tab>

In this event i can access following: sequenceEvent.tab.templateLabel.context but this context is undefined. How can i set this to e.g. sequence.sequenceName?

like image 452
Quimcode Avatar asked Dec 18 '25 08:12

Quimcode


1 Answers

There is a way to do this but it's a bit of a hack. If you assign your 'sequence' data to the 'label' input of the tab, you can get it from the MatTabChangeEvent. This only works because you are using template labels so you can 'repurpose' the label input:

<mat-tab-group (selectedTabChange)="onSequenceChangeEvent($event)">

<mat-tab *ngFor="let sequence of sequencesForSelectedScope" [label]="sequence">

    <ng-template mat-tab-label>
        <span>{{sequence.sequenceName}}</span>
    </ng-template>

</mat-tab>

onSequenceChangeEvent(event: MatTabChangeEvent) {
  console.log(event.tab.textLabel.sequenceName);
}
like image 183
G. Tranter Avatar answered Dec 19 '25 23:12

G. Tranter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!