0
我試圖取消選定一個複選框。我有一個帶有複選框的項目列表,所以當我點擊複選框時,這個項目將被推送到數組,並且我將在另一個div中顯示它。然後,該div有一個刪除按鈕,所以當我刪除該特定項目。該項目應該被刪除,並且已被選中的項目將被取消選中。我希望你明白我在說什麼。我的英語不好。這是我的代碼。如何取消選中選中的複選框,Angular 2
the first div
<tr *ngFor = "let item of rows">
<td style ="text-align: center"><md-checkbox
(change)="onChange(item, $event.checked)" [value] = "item" name = "checklist"></md-checkbox></td>
<td> {{ item.disclosureNumber }}</td>
<td> {{ item.title }}</td>
<td><button md-icon-button (click)="openModal(item)"><i class="material-icons">find_in_page</i></button></td>
</tr>
,然後這是(change)
事件,將在陣列推動和刪除項目
onChange(gridData: Array<any>, isChecked: boolean) {
if(isChecked) {
//push item if true
this.FormArray.push(gridData);
} else {
//remove item if false
let index = this.FormArray.indexOf(gridData);
console.log(index);
this.FormArray.splice(index, 1);
}
則顯示所有在另一個DIV
<tr *ngFor = "let item of FormArray">
<td> {{ item.disclosureNumber }}</td>
<td> {{ item.title }}</td>
<td><button md-icon-button (click) = "removeItem(item)"><i class="material-icons">delete</i></button></td>
</tr>
,如果我的工作很好的FormArray
數據點擊刪除按鈕它將刪除到FormArray
removeItem(item): void {
let pointer = this.FormArray.indexOf(item);
if (pointer > -1) {
this.FormArray.splice(pointer, 1);
}
問題是,即使我從該FormArray中刪除該項目,之前選擇的複選框仍然處於選中狀態。我怎樣才能強制取消選中該複選框。請幫助我,謝謝。 PS我是新手。
謝謝主席先生。它爲我工作 –