我有一个表单,我想通过检查电子邮件是否存在来执行 http 验证,但它返回错误。这是我的表格:
在表单组件上
constructor(
private _formBuilder:FormBuilder,
private _validationService:ValidationService
) { }
ngOnInit() {
this.resetForm = this._formBuilder.group({
email:['',Validators.compose([
this._validationService.emailExistsValidator //this returns an error
,Validators.required
])]
})
在验证服务上
constructor(
public _authService:AuthService //tried also with private
){}
emailExistsValidator(control){
if(control.value != undefined) {
this._authService.checkExists("email")
.map(response => {
if (!response) {
return {'emailNotExists': true};
}
});
}
}
在 _authservice (它是一个服务)上
checkExists(value:string):Observable<any>{
return this._httpclient.get(this.authurl+value) //httpclient attches the headers
.map(response => {
return response
});
}
现在收到此错误
Argument of type '((control: any) => void)[]' is not assignable to4
parameter of type 'ValidatorFn[]'.
Type '(control: any) => void' is not assignable to type 'ValidatorFn'.
Type 'void' is not assignable to type '{ [key: string]: any; }'.)
我还需要做什么?
https://angular.io/docs/ts/latest/api/forms/index/FormBuilder-class.html
异步验证器是第三个参数
email:['', [Validators.required], [
this._validationService.emailExistsValidator.bind(this)
]]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)