简体   繁体   English

Mat-tab点击事件

[英]Mat-tab click event

I am using angular universal with angular material 2, and therefore I have only managed to get clicks to work (as far as user events is concerned). 我正在使用角度通用和角度材料2,因此我只是设法获得点击工作(就用户事件而言)。 Is it possible to attacth a (click) attribute from a tab to change the index and pull dynamic data. 是否可以从选项卡中获取(单击)属性以更改索引并提取动态数据。

I used to have a method getAlbums which retrieves an array of pictures on selectedIndexChange, now that this is not an option is there another way of doing it? 我曾经有一个方法getAlbums,它检索selectedIndexChange上的图片数组,既然这不是一个选项,还有另一种方法吗?

The only other way is to have a separate button to control the tab index. 唯一的另一种方法是使用单独的按钮来控制选项卡索引。

I can get click event or mouse event with below code 我可以通过以下代码获得点击事件或鼠标事件

Html HTML

<mat-tab-group disableRipple="true" [selectedIndex]="selectedPageIndex">
  <mat-tab *ngFor="let tabData of tabsData;">
    <ng-template mat-tab-label>
      <div (mousedown)="navigate($event, tabData)"> <!-- From here you can get all event and can pass data from *ngFor -->
        <mat-icon *ngIf="!!tabData.icon"> {{ tabData.icon }}</mat-icon>
        <span *ngIf="!tabData.onlyIcon"> {{ tabData.name }}</span>
      </div>
    </ng-template>
  </mat-tab>
</mat-tab-group>

Style 样式

.mat-tab-label {
  padding: 0;
  height: 40px;
}
.mat-tab-label-content {
  padding: 0 8px;
}
.mat-tab-label-content > div {
  line-height: 40px;
}

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

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