【发布时间】:2022-01-24 21:13:17
【问题描述】:
我有一个 Angular 材料表,并希望在整个列上放置一个 ngIf,以便整个列、标题和数据单元格仅在条件为真时显示。我可以将它放在数据单元格上,但我似乎不知道如何将它放在 ng-container 或 mat-header-cell 上。
我尝试使用 ngFor,然后使用 ngIf,我尝试将标题包装在 div 或表标题 & 行中,但没有成功。
result 是对象,具有 websiteUrl 属性
<table mat-table matSort [dataSource]="dataSource">
<ng-container matColumnDef="websiteUrl">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Website Link</th>
<td mat-cell *matCellDef="let result">
<div *ngIf="showWebsiteLink===1">
<div *ngIf="websiteLinkVisible(result)">
<a (click)="copyLink(result.websiteUrl)">
Copy Link
</a>
</div>
</div>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
【问题讨论】:
标签: html angular html-table angular-material