How can I implement my custom Validator in Angular 2?
I found this plunker:
constructor(private fb: FormBuilder) {
this.form = fb.group({
\'
// Control handling
this.form = fb.group({
'singleSelection': ['Rio', this.text({min: 10})]
});
// Text function to handle min value
public static text(config = {}): ValidatorFn {
return (control: Control): {} => {
if(!control) {
return null;
}
let c: string = control.value;
if(config.min) {
if(c.length < config.min) {
return {
"This field must have at least " + config.min + " characters."
};
}
}
}}