[英]How can I access the Template References of my ViewChildren?
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:以及 .ts 文件中的 ViewChildren:
@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?如何访问 my.ts 代码中每个选项卡(#myFirstTab 和 #mySecondTab)的实际模板引用? 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...
我需要一种方法来区分我的标签,而 label 文本不好,因为它可能会有所不同......
Edit: I specifically asked for @ViewChildren and not @ViewChild.编辑:我特别要求@ViewChildren 而不是@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 .
在这种情况下,我不想在 my.ts 文件中声明每个 Viewchild 。
ViewChild directive ? ViewChild 指令? eg
例如
@ViewChild('myFirstTab') myFirstTab: MatTab;
@ViewChild('mySecondTab') mySecondTab: MatTab;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.