Requiring a checkbox to be checked

后端 未结 11 1925
猫巷女王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:20

    Since Angular 2.3.1 you can use Validators#requiredTrue:

    Component:

    this.formGroup = this.formBuilder.group({
      cb: [false, Validators.requiredTrue]
    });
    

    Template:

    Required

    STACKBLITZ DEMO

提交回复
热议问题