I need to get the value of whatever tab the user clicks on. Here's what I have so far:
<mat-tab-group (selectedTabChange)="getLabel($event)" #tabGroup>
<mat-tab label="{{ thing.name }}" *ngFor="let thing of things | async" #tab>
....
</mat-tab>
</mat-tab-group>
TS - Database Fetch:
thingsCollection: AngularFirestoreCollection<Intf>;
things: Observable<Intf[]>;
ngOnInit() {
this.thingsCollection = this.afs.collection(placeToSearch2);
this.things = this.thingsCollection.valueChanges();
}
The issue is that I also need the value of the label
property of the tab that the mat-tab-group
first loads. (selectedTabChange)
only fires when the user manually clicks on a tab. That's good, but doesn't give me the label of the first tab.
There was a similar question here with a good answer, but the commenter seemed to ghost on me when I asked him my particular question more clearly. The answer that he provided was close to what I need:
ngAfterViewInit() {
console.log('afterViewInit => ', this.tabGroup.selectedIndex); // Close, but no cigar
}
The above solution only gives me the index (which is almost always 0), not the label
. How can I get the label? The Angular Tab reference shows there is a textLabel property. I think this might be the answer, but it uses @Input which I'm not familiar with. Can someone please help me use it?