我有一個ng-template被重用作為表頭。
<ng-template
let-table="table"
let-column="column"
let-label="label"
#tableHeaderTemplate
>
<th [appSort]="table" sort-order="" [attr.sort-key]="column">
<div>
<span>{{ label }}</span>
<span> (asc) </span>
<span> (desc) </span>
</div>
</th>
</ng-template>
單擊列標題時,表的資料被排序。我需要根據屬性顯示(asc)或除列之外。(desc)sort-order
在下面檢查我的代碼示例:
https://stackblitz.com/edit/angular-ivy-ijcuy3?file=src/app/app.component.html
uj5u.com熱心網友回復:
您可以使用[hidden]屬性隱藏元素并通過為表頭指定識別符號來獲取排序鍵屬性的值。
<th #tableHeader [appSort]="table" sort-order="" [attr.sort-key]="column">
<div>
<span>{{ label }}</span>
<span [hidden]="tableHeader.getAttribute('sort-order') !== 'asc'"> (asc) </span>
<span [hidden]="tableHeader.getAttribute('sort-order') !== 'desc'"> (desc) </span>
</div>
</th>
</ng-template>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/436127.html
標籤:javascript html 有角度的 打字稿 角度指令
上一篇:類中的getter始終未定義
