I have this piece of code that whatever I try, I can not get passed the following error.
Error: Property 'EmailValidator' does not exist on 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 inject the EmailValidator:
this.fb.group({
email: ['', UserValidators.EmailValidator]
});
You should create an instance of this class to be able to access it, like this:
var userValidators : IUserValidators = new UserValidators();
userValidators.EmailValidator(ctrl);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加