我有墊表,我制作了一個按鈕,如果長度 > 某個數字
,則隱藏/取消隱藏表格單元格中的文本,但它作業不正確,此按鈕打開每個單元格中的所有文本,按鈕僅適用于第一個單元格
<ng-container matColumnDef="Test">
<th mat-header-cell *matHeaderCellDef mat-sort-header >Test</th>
<td mat-cell *matCellDef="let row; let i = index;">
<ng-container>
{{ show ? (row.Test | slice:0:100) : row.Test}}
<button mat-raised-button class="show-less-button" color = 'primary' type="button" *ngIf="row.Test.length > 5;" (click)="( show == i ? show : show = i )"> {{ ((show == i)) ? 'Show less' : 'Show more' }}
</button>
</ng-container>
</td>
</ng-container>
uj5u.com熱心網友回復:
您必須每行隔離它,因為“顯示”將用于整個組件,然后只有一個。像這樣的東西:
<ng-container matColumnDef="Test">
<th mat-header-cell *matHeaderCellDef mat-sort-header >Test</th>
<td mat-cell *matCellDef="let row; let i = index;">
<ng-container>
{{ row.show ? (row.Test | slice:0:100) : row.Test}}
<button
mat-raised-button
class="show-less-button"
color='primary'
type="button" *ngIf="row.Test.length > 5;"
(click)="row.show = !row.show">
{{ ((row.show)) ? 'Show less' : 'Show more' }}
</button>
</ng-container>
</td>
</ng-container>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/391048.html
