【问题标题】:load function in mat-tab when selected - Angular 2 material using mat-tab-group [duplicate]选择时在 mat-tab 中加载功能-使用 mat-tab-group 的 Angular 2 材料 [重复]
【发布时间】:2020-04-08 10:29:23
【问题描述】:

我如何将action添加到mat-tab 选择时

在我的情况下,我想在选择卡时设置laodCard=true

这是我写的代码,但是操作(click) 不起作用

<mat-tab label="second tab" (click)="loadCards(true)">
       <app-card [load]="laodCard" >
       </app-card>
</mat-tab>

【问题讨论】:

    标签: angular angular9 mat-tab


    【解决方案1】:

    查看 mat-tab-group 的文档: https://material.angular.io/components/tabs/api#MatTabGroup

    您可以在选项卡组级别设置选项卡更改的侦听器。 在该侦听器中,您可以指定切换到任何选项卡时应该发生的情况。

    这是一个小例子:

    模板:

    <mat-tab-group color="primary" (selectedTabChange)="onLinkClick($event)">
        <mat-tab label="second tab">
           <app-card [load]="laodCard" >
           </app-card>
        </mat-tab>
    </mat-tab-group>
    

    组件:

    import { MatTabChangeEvent } from '@angular/material/tabs';
    
    // ...
    
    onLinkClick(event: MatTabChangeEvent) {
    
      //console log all the data that the event returns
      console.log('event => ', event);
      console.log('index => ', event.index);
      console.log('tab => ', event.tab);
    
    
      //replace the string here with the data returned by the last console.log
      if(event.tab == "your selected tab") {
          this.loadCards(true); 
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-06-15
      • 2022-10-16
      • 2021-01-23
      • 2020-11-24
      • 2022-12-22
      • 2020-09-28
      • 2018-12-16
      • 2019-02-25
      • 2018-10-09
      相关资源
      最近更新 更多