I am using angular reactive form. how can i patch or set data to array of check-boxes.I have array like this
departmentList = [
{id: 1, name: 'Dermatolgy'},
{id: 2, name: 'Surgery'},
{id: 3, name: 'Dental'},
{id: 4, name: 'SkinCareLaser'},
];
Let Suppose i want to set true or checked Surger .(on base of DB data).
I am using following code for adding data on registration user.
<div *ngFor="let item of departmentList">
<input type="checkbox" formControlName="departmentControl"
name=
value=""
(change)="selectDepartment($event,item)">
<span></span>
</div>
Class.TS
selectedDepartment: any = [];
selectDepartment(event: any, item: any) {
console.log(event.checked);
if (event.target.checked) {
this.selectedDepartment.push(item.id);
}
else {
let updateItem = this.selectedDepartment.find(this.findIndexToUpdate, item.id);
let index = this.selectedDepartment.indexOf(updateItem);
this.selectedDepartment.splice(index, 1);
}
console.log(this.selectedDepartment);
}
that's working fine.
Question : how can i patch or set data to array on Update Function on base of another arrays data that is fetched from server .
Aucun commentaire:
Enregistrer un commentaire