简体   繁体   English

Angular2 +使用NgFor创建具有相同内容的mat-tab

[英]Angular2+ Using NgFor to create mat-tab with the same content

I am using ngFor to create some tabs according to a list with the mat-tab material. 我正在使用ngFor根据带有mat-tab材料的列表创建一些标签。

However, I would like to only have a unique content. 但是,我只想拥有一个独特的内容。 Indeed, the content is a graph and only the data changed. 实际上,内容是一个图形,只有数据发生了变化。 Therefore, when I click on one of the tabs, it calls the function onTabChanged() and the variable data is updated in the < nvd3 >. 因此,当我单击选项卡之一时,它将调用函数onTabChanged() ,并且变量数据将在<nvd3>中更新。

This does not work properly. 这不能正常工作。 Because it creates three times nvd3. 因为它创建了nvd3的三倍。

In fact, I would like the tabs acting like a button. 实际上,我希望选项卡像按钮一样。 Because I tried some buttons but I prefer the design of the tabs. 因为我尝试了一些按钮,但是我更喜欢标签的设计。

<mat-tab-group class="col-10 offset-1" (selectedTabChange)="onTabChanged($event)">
  <mat-tab label={{tab.type}} *ngFor="let tab of datasetList; let index = index">
    <div>
      <nvd3 #nvd3 [options]="chart" [data]="data"></nvd3>
    </div>
  </mat-tab>
</mat-tab-group>

我认为您应该使用mat-tab-nav-bar而不是mat-tab-group

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM