类型'typeof ...'不存在TypeScript'...' [英] TypeScript '...' does not exist on type 'typeof ...'
本文介绍了类型'typeof ...'不存在TypeScript'...'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码,无论尝试如何,都无法传递以下错误.
I have this piece of code that whatever I try, I can not get passed the following error.
错误: 属性'EmailValidator'在'typeof UserValidators'类型上不存在.
Error: Property 'EmailValidator' does not exist on type 'typeof UserValidators'.
代码:
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 {};
}
}
这是我尝试注入EmailValidator的方式:
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);
这篇关于类型'typeof ...'不存在TypeScript'...'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文