Consider these material tabs in my template:
<mat-tab #myFirstTab>Something</mat-tab>
<mat-tab #mySecondTab>Something else</mat-tab>
And the ViewChildren in the.ts file:
@ViewChildren(MatTab)
private allTabs: QueryList<MatTab>;
public ngAfterViewInit() {
this.allTabs.forEach(tab => console.log('tab: ', tab));
}
How can I access the actual template references of each tab (#myFirstTab and #mySecondTab) in my.ts code? Is it possible at all this way around? I need a way to differentiate my tabs , and the label text is not good because it can vary...
Edit: I specifically asked for @ViewChildren and not @ViewChild. Of course I know the other way around. In this case, I do not want to have to declare each Viewchild in my.ts file .
ViewChild directive ? eg
@ViewChild('myFirstTab') myFirstTab: MatTab;
@ViewChild('mySecondTab') mySecondTab: MatTab;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.