Requiring a checkbox to be checked

后端 未结 11 1871
猫巷女王i
猫巷女王i 2020-12-25 09:51

I want a button to be disabled until a checkbox has been checked using a FormBuilder for Angular. I don\'t want to explicitly check the value of the checkbox and would prefe

11条回答
  •  生来不讨喜
    2020-12-25 10:14

    Create a method to detect any changes

    checkValue(event: any) {
        this.formulario.patchValue({
          checkboxControlName: event.target.checked
        })
    }
    

    Put that method on an event change and ngModel required properties

    
    

    And use the convetional way to validate

    this.formulario = new FormGroup({
      checkboxControlName: new FormControl('', [Validators.required])
    });
    

    Source

提交回复
热议问题