binding data to angular checkbox

后端 未结 3 1016
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 01:51

I managed to bind the data from this.empDetails.services correctly on the UI, checkboxes are checked correctly, and also listed all the checkboxes options.

3条回答
  •  无人及你
    2020-12-04 02:18

    you forget to set the new value of the form Array sservices :

    onCheckChange(event) {
      const sservicesFormArray: FormArray =
        this.updateSvcForm.get('sservices') as FormArray;
    
    
      if (event.target.checked) {
        sservicesFormArray.push(new FormControl(event.target.value));
      }
      else {
        let i: number = 0;
        sservicesFormArray.controls.forEach((ctrl: FormControl) => {
          if (ctrl.value == event.target.value) {
            sservicesFormArray.removeAt(i);
            break;
          }
          i++;
        });
      }
      // set the new value of sservices form array
      this.updateSvcForm.setControl('sservices', sservicesFormArray);
    }
    

提交回复
热议问题