回路检查值角4
问题描述:
我需要发送每一个员工我检查postCouncilAbsence功能参数,我想打一个循环来每个员工,然后我查过他送的参数..使用打字稿任何帮助吗?回路检查值角4
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>{{attendance.Employee_ID}}</td>
<td > {{attendance.Emp_Name}} </td>
<td>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox (change)="onChange(attendance.Employee_ID,$event.target.checked)" > {{attendance.isAttend}}
</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>
我想给每个员工的ID给这个函数:
postCouncilAbsence(absence, userId){
let url = 'http://api.azharcouncil.com/api/CouncilAbsences/PostCouncilAbsence?Council_Id='+13+'&Emp_Id='+absence+'&User_Id='+userId;
let headers = new Headers({ 'Content-Type': 'text/plain' });
let options = new RequestOptions({ headers: headers });
return this.http.post(url, JSON.stringify(absence), options);
}
答
它看起来就像你在校准时已经发回ID一样l onChange()
。你可以捕捉它,然后在一个变量,然后使用它,当你调用postCouncilAbsence()
component.ts
employeeId: string;
onChange(attendance:string, isChecked: boolean) {
//your code
this.employeeId = attendance;
}
postCouncilAbsence(absence, userId){
const employeeId = this.employeeId; // don't need this but it's here to show you
//your code and you can use this.employeeId
}
+0
感谢您的帮助,您 –
+0
太客气了。 –
你在哪里调用'onattendanceSave()'? –
对不起,我编辑我的问题 –
为什么不在你'* .ts'文件创建一个变量您的来电'的onChange()'期间操纵和再使用,当你调用'postCouncilAbsence()'? –