一段时间后,我的控制台上不断出现错误。谁能告诉我是因为 API 不稳定吗?我是 Angular 的初学者
异步验证器类:
import { AsyncValidator, FormControl } from '@angular/forms'
import { AuthService } from '../auth.service'
import { Injectable } from '@angular/core';
import { map, catchError } from 'rxjs/operators'
import { of } from 'rxjs';
@Injectable ({providedIn : 'root'})
export class UniqueUsername implements AsyncValidator{
constructor(private authService: AuthService){}
validate = (control: FormControl) => {
const { value } = control;
return this.authService.usernameAvailable(value).pipe(
map(()=> {
return null;
}),
catchError(err=> {
if(err.error.username){
return of({ nonUniqueUsername: true })
}
else{
return of({ noConnection: true})
}
})
);
}
}
服务:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(private http: HttpClient) { }
usernameAvailable(username: string){
return this.http.post<any>(' https://api.angular-email.com/auth/username ', {
username: username
})
}
}
我的控制台上不断出现的错误: