我创建了自定义验证指令:
import {Directive} from '@angular/core';
import {AbstractControl, NG_VALIDATORS, ValidationErrors, Validator, ValidatorFn} from "@angular/forms";
@Directive({
selector: '[validator]',
providers: [{provide: NG_VALIDATORS, useExisting: CIFValidator, multi: true}]
})
export class CIFValidator implements Validator {
constructor() {}
public validate(c: AbstractControl): ValidationErrors | any {
return null
}
}
我目前将它用作属性,但是如果我想在反应形式配置中使用它应该怎么做,如下所示:
this.form = this.formBuilder.group({
someField: ['', [Validators.NewValidator]]
});
?