【发布时间】:2022-06-11 16:26:06
【问题描述】:
我遇到了一个问题,即 http 请求从上次加载的请愿书中获取数据。而不是来自上一个 http 请求。
有什么方法可以停止最后一次通话并获得新的通话吗?
组件
this.searchForm$.valueChanges
.pipe(debounceTime(500))
.subscribe((selectedValue) => {
this.loading = true;
this.sExperienceSearch = {...selectedValue.sExperience,...selectedValue.sExperience2,...selectedValue.sExperience3,...selectedValue.sExperience4}
this.sExperienceSearch.importanceMap = {...selectedValue.sExperience.importanceMap,...selectedValue.sExperience2.importanceMap}
this.apiService
.getSearch(this.sExperienceSearch)
.subscribe((data: any) => {
this.firstCall = false;
this.loading = false;
this.selectedValue = this.sExperienceSearch;
this.searchData = data;
this.numVendors = this.searchData.numVendors
? this.searchData.numVendors
: 0;
});
});
}
服务
return this.httpClient
.post<any[]>('/api/advanced-search', body, httpOptions)
.pipe(
distinctUntilChanged(),
map((data) => {
return data;
}),
catchError((error) => {
return throwError('Something went wrong!');
})
);
【问题讨论】:
标签: angular typescript