0

我想显示所有员工,然后检查缺勤情况,然后返回缺勤人员

这是我的表格:

            <!-- Modal body -->
            <div class="modal-body" >
             <form [formGroup]="attendanceForm">
              <div class="row">
                <table class="table table-hover table-condensed text-center table-bordered">
                  <thead>
                    <tr>
                        <th> Names </th>
                        <th>  Attendance </th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr *ngFor="let attendance of attendances">
                       <td > {{attendance.Emp_Name}} </td>
                       <td> 
                           <div class="form-check">
                              <label class="form-check-label">
                                <input type="checkbox (change)="onChange(attendance.isAttend,$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>

组件.ts:

this.attendanceForm = this.fb.group({
        'isAttend' : this.fb.array([])
    })

onattendanceSave(form:NgForm){
console.log(this.attendanceForm.value);
        }
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);
    }
}

我显示了所有员工(attendance.Emp_Name),并在每个员工旁边显示了他的复选框,如果他缺席,那么我会检查它.. 我怎样才能使用 Angular 4 只返回检查过的员工?现在 isAttend 记录为空

4

0 回答 0