【问题标题】:How to show buttons for only first row in mat-table如何在 mat-table 中仅显示第一行的按钮
【发布时间】:2019-02-01 19:12:13
【问题描述】:

我有一个显示正在执行的作业列表的垫表。 目前我在所有行前面都有停止和重新执行按钮。 现在我只想在第一行显示按钮。 我该怎么做?

mat-table 中按钮的代码

<ng-container matColumnDef="actions">
    <mat-header-cell *matHeaderCellDef> </mat-header-cell>
    <mat-cell *matCellDef="let element; let index = index">
        <button
            mat-icon-button
            (click)="stop_exec_job(element)"
            matTooltip="Stop Executing the Job"
            [disabled]="element.status == 'Completed' || element.status == 'FINISH'"
        >
            <!-- Edit icon for row -->
            <i class="material-icons" style="color:red"> stop </i>
        </button>
        <!-- Delete icon for row -->
        <button
            mat-icon-button
            (click)="re_run_job(element)"
            matTooltip="Re-Run the Job"
            [disabled]="
                element.status == 'RUNNING' ||
                element.status == 'Pending'
            "
        >
            <i class="material-icons" style="color:green">
                cached
            </i>
        </button>
    </mat-cell>
</ng-container>

【问题讨论】:

    标签: javascript angular typescript angular-material


    【解决方案1】:
    <button *ngIf="index === 0"
      ...>...</button>
    

    ngIf doc

    【讨论】:

    • 我这样做了..但是按钮消失了..我什至将索引更改为 1 但没有用
    • 没关系修复它......我犯了一个愚蠢的错误......你的代码工作正常......非常感谢
    猜你喜欢
    • 1970-01-01
    • 2018-11-13
    • 1970-01-01
    • 1970-01-01
    • 2019-11-20
    • 1970-01-01
    • 2021-07-20
    • 2019-06-16
    • 2018-04-04
    相关资源
    最近更新 更多