簡體   English   中英

如何訪問我的 ViewChildren 的模板參考?

[英]How can I access the Template References of my ViewChildren?

考慮我的模板中的這些材料選項卡:

<mat-tab #myFirstTab>Something</mat-tab>
<mat-tab #mySecondTab>Something else</mat-tab>

以及 .ts 文件中的 ViewChildren:

  @ViewChildren(MatTab)
  private allTabs: QueryList<MatTab>;

  public ngAfterViewInit() {
    this.allTabs.forEach(tab => console.log('tab: ', tab));
  }

如何訪問 my.ts 代碼中每個選項卡(#myFirstTab 和 #mySecondTab)的實際模板引用 有可能嗎? 我需要一種方法來區分我的標簽,而 label 文本不好,因為它可能會有所不同......

編輯:我特別要求@ViewChildren 而不是@ViewChild。 我當然知道反過來。 在這種情況下,我不想在 my.ts 文件中聲明每個 Viewchild

ViewChild 指令 例如

@ViewChild('myFirstTab') myFirstTab: MatTab;
@ViewChild('mySecondTab') mySecondTab: MatTab;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM