2017-10-17 5 views
0

사용자의 전자 메일이 고유한지 여부를 확인하는 사용자 지정 검사기가 있습니다.맞춤형 비동기 유효성 검사기가 보류 중 상태로 유지됨

I에 유래와 인터넷에서 관련 항목을 검색하지했지만 아무 도움

내가 (요청을 보내는) 형태로 입력을주는거야, 요청이 보류 상태로 유지하고 결의를 doesnot.

필자는 우체부에서 백엔드를 테스트했는데 예상대로 작동하고 클라이언트 측이나 각도 측에 문제가 있습니다.

emailUniqueValidator (control: AbstractControl): Promise<{[key: string]: any}> | Observable<{[key: string]: any}> { 
    return new Promise((resolve, reject) => { 
     this.userService.checkEmailUnique(control.value).subscribe((response: Response) => { 
     const body = response.json(); 
     if (body.found === false) { 
      resolve(null); // email is unique 
     } else { 
      reject({emailUniqueValidator: true}); // email is not unique 
     } 
     }); 
    }); 
    } 

내가 폼 컨트롤의 값을 변경하고있어, 보류중인 클래스가 나타납니다,하지만 해결하기로 영원히 대신에 스틱 다음과 같이

유효성 검사 기능입니다. 다음과 같이

나는 이메일 양식 제어 할 수 있습니다 :

'email': new FormControl('', [ 
     Validators.required, 
     Validators.email 
     ], this.emailUniqueValidator.bind(this) 
), 

다음과 같이 내 사용자 서비스는 다음과 같습니다 영원히

유효성 검사기 시간에 해결하고 머물 수없는 이유
checkEmailUnique (email: string): Observable<Response> { 
    return this.http.post('http://localhost:3000/user/email', {email}, { withCredentials: true }); 
    } 

보류?

편집 : 다음 코드는 서비스를 잘에서 값을 받고, 내가 콘솔에 응답을 기록하여 확인했습니다있다

.

이메일이 데이터베이스에없는 경우 문제가 해결되었지만 이메일이 이미있는 경우 오류가 발생하고 상태는 보류 중으로 남습니다.

return new Promise((resolve, reject) => { 
     this.userService.checkEmailUnique(control.value).subscribe((response: Response) => { 
     console.log(response); 
     response.json().found ? reject({emailUniqueValidator: true}) : resolve(null); 
     }, (error: any) => reject({emailUniqueValidator: true})); 
}); 

답변

0

왜 관찬할만한 시련을 감출 것입니까? 이것을 시도해보십시오 :

emailUniqueValidator (control: AbstractControl): Observable<{[key: string]: any}> { 
    return this.userService.checkEmailUnique(control.value) 
       .map(r => r.json()) 
       .map(r => (r.found) ? {emailUniqueValidator: true} : null); 
} 
+0

코드를 시도했지만 상태가 여전히 보류 중입니다. 왜 이런 일이 일어 났는지 말할 수 있습니까? –

+0

do() 연산자를 사용하여 디버깅해야합니다. 아무 것도 통과하지 못했습니까? 이것이 작동해야합니다. 일부 문제는 다른 곳에서 발생합니다. – bryan60

관련 문제