// email是否注册校验器
emailRegisteredValidator(control: FormControl): Observable<any>{
if (control.value) {
return control.valueChanges
.debounceTime(1000)
.distinctUntilChanged()
.mergeMap(() => this.http.checkEmailHasRegisted(control.value))
.mergeMap(data => Observable.of(null))
.catch(this.handleError)
.first()
} else {
return Observable.of(null)
}
}
private handleError(error:any) {
console.log(error)
if(error.status === 400 ) {
return Observable.of({'emailCheck': true})
} else {
return Observable.of(null);
}
}