角度自定义验证和Firebase

时间:2018-09-27 13:23:30

标签: angular firebase validation

我试图根据每个课程的效果来验证服装验证,这取决于Web上的课程,并且验证返回null或false,但html中的错误消息未更改

验证码为

export class customValidation{
  static duplicateEmail(afs:AngularFirestore){
    return (control:AbstractControl)=>{
      let email =  control.value;
      return afs.collection<any>(`users`, ref=>ref.where('email','==',email)).valueChanges()
                .pipe(
                  debounceTime(500),
                  take(1),
                  map(data => data.length ? {duplicateEmail:false} : null)
                ).subscribe(data=> {
                  console.log(data)
                  return data;
                })
    }
  }
}

表单构建器的鳕鱼是

    this.signupForm = this.FB.group({
  email: ['', [
    Validators.required,
    Validators.email,
    customValidation.duplicateEmail(this.afs)
  ]],
  password:['', [
    Validators.required
  ]]
})

并且html代码是

  {{signupForm.controls.email.invalid}}
<div *ngIf="email.invalid && email.dirty" class="danger-text">
    {{email.value}} is not available
  </div>

enter image description here

我已将结果打印在控制台中,并且返回的null或false取决于电子邮件值,但email.invalid保持为真

0 个答案:

没有答案