Quando eu coloco um usuario existente ele mostra a mensagem 'user available'. Segue o codigo:
user-not-taken.validator.service.ts
checkUserNameTaken(){
return (control: AbstractControl) => {
return control.
valueChanges.
pipe(debounceTime(300)).
pipe(switchMap(userName =>
this.signupService.checkUserNameTaken(userName)
)).
pipe(map(isTaken =>
isTaken ? {userNameTaken: true } : null
)).
pipe(first());
}
}
signup.service.ts
checkUserNameTaken(userName: string){
return this.http.get(API_URL + '/user/exists/'+userName);
}
signup.component.ts
userName: ['',
[
Validators.required,
lowerCaseValidator,
Validators.minLength(2),
Validators.maxLength(30)
],
this.userNotTakenValidatorService.checkUserNameTaken()
],
signup.component.html
<ap-vmessage
text="User name already taken!"
*ngIf="signupForm.get('userName').errors?.userNameTaken"
></ap-vmessage>
<small *ngIf="signupForm.get('userName').valid" class="text-success">User available!</small>
OBS: as outras validações funcionam normalmente