填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

CheckboxRequiredValidator

该指令会借助 NG_VALIDATORS 绑定把 required 验证器添加到任何带有 required 属性的检查框控件上。

A Directive that adds the required validator to checkbox controls marked with the required attribute. The directive is provided with the NG_VALIDATORS multi-provider list.

参见

NgModules

选择器

  • input[type=checkbox][required][formControlName]
  • input[type=checkbox][required][formControl]
  • input[type=checkbox][required][ngModel]

继承自 RequiredValidator

说明

使用模板驱动表单为复选框添加必填项验证器

Adding a required checkbox validator using template-driven forms

下面的例子展示了如何为一个带有 ngModel 绑定的检查框添加必填项验证器。

The following example shows how to add a checkbox required validator to an input attached to an ngModel binding.

<input type="checkbox" name="active" ngModel required>
      
      <input type="checkbox" name="active" ngModel required>
    

方法

Method that validates whether or not the checkbox has been checked. Returns the validation result if enabled, otherwise null.

validate(control: AbstractControl): ValidationErrors | null
      
      validate(control: AbstractControl): ValidationErrors | null
    
参数
control AbstractControl
返回值

ValidationErrors | null

继承自 RequiredValidator