Reputation: 32550
I have to add custom validator for reactive forms. I will do that in form of
export class CustomValidators {
isMemberOf(allowedValues: any[]) {
return (ctrl: AbstractControl) => {
//whatever
};
}
}
How can I declare such method so it would appear as part of existing Validators
class that is provided with forms module so it will be accessible like Validators.isMemberOf(...)
just like Validators.required
Upvotes: 0
Views: 209
Reputation: 486
Check module augmentation, it could be helpful to your needs
import { Validators } from "your-module";
declare module "your-module" {
interface Validators {
isMemberOf(allowedValues: any[]): any;
}
}
Validators.prototype.isMemberOf = (allowedValues: any[]) => {...}
Upvotes: 1