2016-11-23 75 views
0

我有以下代碼:Angular2材料訪問標籤外面

<md-tab-group> 
      <md-tab *ngFor="let section of sectionList"> 
     <template md-tab-label> 
<span (click)="selectedSection=section"> 
      {{section.name}} 
</span> 
     </template> 
     </md-tab> 
     </md-tab-group> 

如何可以顯示標籤循環外的當前選擇部(section對象)的數據?

我試圖添加一個span(click)但它不能觸發。

+0

你能否提供[Plunker](https://plnkr.co/)? –

回答

0

該選項卡組具有一個selectedIndex屬性,因此您可以爲其創建一個template reference然後使用它。

<md-tab-group #tabGroup> 
<md-tab *ngFor="let section of sectionList"> 
    <template md-tab-label> 
    <span (click)="selectedSection=section"> 
     {{section.name}} 
    </span> 
    </template> 
</md-tab> 
</md-tab-group> 
<div>{{sectionList[tabGroup.selectedIndex].name}}</div>