如何以角度檢查當前頁面中的所有條目?如果我單擊全選復選框,則將選擇所有條目。但是,如果我有一個包含 50 個用戶的用戶串列,并且每頁將它們分頁 5 個,如果我按下復選框,它們將全部被選中,而不僅僅是所選頁面上的條目。我該如何解決這個問題?
https://stackblitz.com/edit/ngx-pagination-example-hq94bl?file=app/app.component.ts
我的 stackblitz 供參考
uj5u.com熱心網友回復:
演示:Stackbliz
我認為您應該使用 getter 函式來檢查頁面上的所有專案是否都已檢查,然后檢查所有按鈕 isChecked 將等于 true
get isSelected() {
const itemIndex = 5 * (this.page - 1);
const itemsInCurrentPage = this.usersList.slice(itemIndex, itemIndex 5);
const isSelected = itemsInCurrentPage.every((item) => item.selected);
return isSelected;
}
并使用 ngModel 輸入來更新復選框的狀態
<input
type="checkbox"
[(ngModel)]="user.selected"
(change)="saveSelectedList($event, user.name)"
/>
全部檢查按鈕
<input
type="checkbox"
(change)="selectAll($event, page)"
[checked]="isSelected"
/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/455188.html
標籤:有角度的
