我创建了自定义验证指令:
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]]
});