Validator

An interface that can be implemented by classes that can act as validators.

一个接口,实现了它的类可以扮演验证器的角色。

interface Validator { validate(c: AbstractControl): ValidationErrors | null registerOnValidatorChange(fn: () => void)?: void }

说明

Usage

用法

@Directive({ selector: '[custom-validator]', providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}] }) class CustomValidatorDirective implements Validator { validate(c: Control): {[key: string]: any} { return {"custom": true}; } }

方法

validate(c: AbstractControl): ValidationErrors | null

参数

c

Type: AbstractControl.

返回值

ValidationErrors | null

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

参数

fn

Type: () => void.

返回值

void