如何在 Angular 中的验证指令中触发 ngOnChanges 上的验证函数?
我检测到 ngOnChanges,但它无法触发验证功能
@Directive({
selector: '[uppercase]',
providers: [{
provide: NG_VALIDATORS,
useExisting: RdUppercaseDirective,
multi: true
}]
})
export class RdUppercaseDirective implements Validator, OnChanges {
@Input('uppercase') uppercase: any;
r = new rdValidators;
validate(control: AbstractControl): {
[key: string]: any
} | null {
let u = this.uppercase === 'false' || this.uppercase === false ? false : true;
if(!control.value)
{
return null;
}
if(u === false)
{
return null;
}
var result = (/[a-z]/.test(control.value));
return control.dirty && control.value ? result ? { 'uppercase' : true } : null : null;
}
ngOnChanges(changes: SimpleChanges){
if(changes.uppercase){
//**How to Trigger Validate Function Here!**
}
}
}