i need to send every employee i checked to postCouncilAbsence function parameter, i want to make a loop to loop each employee i checked then send him as parameter .. any help using typescript?
component.ts:
onattendanceSave(form:NgForm){
this.index = this.attendanceForm.value
console.log(this.index);
Object.keys(this.index).forEach( key => {
this.dataStorageService.postCouncilAbsence(this.index,this.Id)
.subscribe(
response => {
console.log('save'+ this.index);
}),
error =>{
console.log('error');
}
});
}
onChange(attendance:string, isChecked: boolean) {
const attendanceFormArray =
<FormArray>this.attendanceForm.controls.isAttend;
if(isChecked) {
attendanceFormArray.push(new FormControl(attendance));
} else {
let index = attendanceFormArray.controls.findIndex(x => x.value == attendance)
attendanceFormArray.removeAt(index);
}
}
component.html:
<form [formGroup]="attendanceForm" >
<div class="row">
<table class="table table-hover table-condensed text-center table-bordered">
<thead>
<tr>
<th> attendances </th>
<th> check </th>
</tr>
</thead>
<tbody>
<tr *ngFor="let attendance of attendances" >
<td hidden></td>
<td > </td>
<td>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox (change)="onChange(attendance.Employee_ID,$event.target.checked)" >
</label>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success" (click)="onattendanceSave(attendanceForm.value)"> save </button>
</div>
</form>
Aucun commentaire:
Enregistrer un commentaire