MaxLengthValidator

A directive which installs the MaxLengthValidator for any formControlName, formControl, or control with ngModel that also has a maxlength attribute.

@Directive({ selector: '[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]', providers: [MAX_LENGTH_VALIDATOR], host: { '[attr.maxlength]': 'maxlength ? maxlength : null' } }) class MaxLengthValidator implements Validator, OnChanges { maxlength: string ngOnChanges(changes: SimpleChanges): void validate(c: AbstractControl): ValidationErrors | null registerOnValidatorChange(fn: () => void): void }

选择器

[maxlength][formControlName] [maxlength][formControl] [maxlength][ngModel]

输入参数

说明

该指令会把 MaxLengthValidator 验证器安装到任何具有 minlength 属性的 formControlNameformControl 或带 ngModel 的控件上。

属性

属性名类型说明
maxlength

方法

ngOnChanges(changes: SimpleChanges): void

参数

changes

Type: SimpleChanges.

返回值

void

validate(c: AbstractControl): ValidationErrors | null

参数

c

Type: AbstractControl.

返回值

ValidationErrors | null

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

参数

fn

Type: () => void.

返回值

void