EmailValidator

A Directive that adds the email validator to controls marked with the email attribute, via the NG_VALIDATORS binding.

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

@Directive({ selector: '[email][formControlName],[email][formControl],[email][ngModel]', providers: [EMAIL_VALIDATOR] }) class EmailValidator implements Validator { set email: boolean | string validate(c: AbstractControl): ValidationErrors | null registerOnValidatorChange(fn: () => void): void }

选择器

[email][formControlName] [email][formControl] [email][ngModel]

输入参数

说明

Example

例子

<input type="email" name="email" ngModel email> <input type="email" name="email" ngModel email="true"> <input type="email" name="email" ngModel [email]="true">

属性

属性名类型说明
email

方法

validate(c: AbstractControl): ValidationErrors | null

参数

c

Type: AbstractControl.

返回值

ValidationErrors | null

registerOnValidatorChange(fn: () => void): void

参数

fn

Type: () => void.

返回值

void