I have this piece of code, no matter what I try, I cannot get the following error.
Error: The property 'EmailValidator' does not exist for the type 'typeof UserValidators'.
Code:
import {EMAIL_REGEX} from '../constants'; import {Control} from 'angular2/common'; export interface IUserValidators { EmailValidator(control: Control) : Object; } export class UserValidators implements IUserValidators { EmailValidator(control: Control) : Object { if (!control.value) { return { required: true }; } else if (control.value) { if (!new RegExp(EMAIL_REGEX).test(control.value)) { return { invalid: true }; } } return {}; } }
This is how I try to enter EmailValidator:
this.fb.group({ email: ['', UserValidators.EmailValidator] });
source share