Javascript angular2中的表单异步验证
我是angular2的新手,我想验证来自服务器的电子邮件地址,但失败了 这是我的表格Javascript angular2中的表单异步验证,javascript,angular,typescript,Javascript,Angular,Typescript,我是angular2的新手,我想验证来自服务器的电子邮件地址,但失败了 这是我的表格 this.userform = this._formbuilder.group({ email: ['', [Validators.required], [this._validationService.emailExistsValidator.bind(this)]], }); 然后是我的_ValidationService 验证服务是带有@Injector的服务 @Injectable()
this.userform = this._formbuilder.group({
email: ['', [Validators.required], [this._validationService.emailExistsValidator.bind(this)]],
});
然后是我的_ValidationService
验证服务是带有@Injector的服务
@Injectable()
export class ValidationService{
constructor(
private _authService:AuthService
){}
emailExistsValidator(control) {
if (control.value != undefined) {
return this._authService.checkExists("email")
.map(response => {
if (!response) {
return {'emailNotExists': true};
}
});
}
}
}
在authservice中,我有(这是另一个执行http请求的服务)
如果
此应指向验证服务
,绑定()
需要
this.userform = this._formbuilder.group({
email: ['', [Validators.required], [this._validationService.emailExistsValidator.bind(this._validationService)]],
});
您需要为代码提供更多上下文。emailExistsValidator()方法位于哪里?this.\u authService
是如何实例化的?抱歉,我更新了这个问题所有这些都是不同的服务,这个。\u authService在构造函数中实例化了另一个问题现在出现了,我只想在用户完成输入电子邮件后进行验证,当前每个按键都有效,我该怎么做呢?当你不想让用户看到验证错误时,就把它隐藏起来。像showEmailValidation:boolean=false代码>
Cannot read property 'checkExists' of undefined
at UsersComponent.webpackJsonp.187.
ValidationService.emailExistsValidator
this.userform = this._formbuilder.group({
email: ['', [Validators.required], [this._validationService.emailExistsValidator.bind(this._validationService)]],
});