Reputation: 2535
I have a checkbox based on selecting the checkbox, the values must be shown in the dropdown. But here, when i "unselect" both the checkboxes and again select both and "unselect" one, then the dropdown values remains same, it doesn't reset. Can anyone help me to sort out this?
Ts:
setFaxId(index: number, faxQue: any) {
faxQue.isChecked = (faxQue.isChecked) ? false : true;
let filteredArr = this.faxqueuelists.filter(x=>x.faxQueueID == faxQue.faxQueueID);
if (faxQue.isChecked) {
this._selectedFaxQueList.push(faxQue.faxQueueID);
this.dropDownFaxQueueList.push(filteredArr[0]);
if(this.dropDownFaxQueueList.length == 1){
this.userGroup.get("DefaultFaxQueue").patchValue(faxQue.faxQueueID);
}
} else {
this._selectedFaxQueList.splice(this._selectedFaxQueList.indexOf(faxQue.faxQueueID), 1);
this.dropDownFaxQueueList.splice(this._selectedFaxQueList.indexOf(faxQue.faxQueueID),1);
this.userGroup.get("DefaultFaxQueue").patchValue("");
}
}
Upvotes: 0
Views: 268
Reputation: 5321
Replace the else
part by this:
let index = this._selectedFaxQueList.indexOf(faxQue.faxQueueID);
this._selectedFaxQueList.splice(index, 1);
this.dropDownFaxQueueList.splice(index,1);
The selected element is already deleted from _selectedFaxQueList
, when doing the indexOf()
second time (in your code), it won't give a proper result.
Upvotes: 1