我有一个自定义验证器,用于检查字段值是否存在。但是,此验证程序在调用后似乎并未完成,因此卡在了待处理状态。我只想在验证器中的请求处于挂起状态时才挂起。我正在使用过滤选项“ First()”,但它没有影响。这是我的验证器:
public articleExistsValidator(formControl: AbstractControl): Observable <ValidationErrors | null > {
return this.ReplacementService.getArticle(this.clientName, formControl.value).pipe(
map(
article => {
if (article) {
this.newEquipmentType = article.equipmentTypeNumber;
return null;
}
}),
catchError ( err => {
return Observable.throw(err.statusText);
}
),
first()
);
}
这是Service中带有另一个Observable的getArticle方法
public getArticle(
clientName: string,
articleName: string
): Observable<Article> {
const url = this.articleUrl + '/';
let searchParams = new HttpParams();
searchParams = searchParams.set('article-number', articleName);
const options = {
headers: this.getHttpHeaders(false),
params: searchParams
};
return (
this.httpClient
.get<Article>(url, options)
)
.first()
.catch((err: any) => Observable.throw(this.errorHandler(err)));
}