--Component.ts--
getGenCoreLabs() {
this.checkinService
.getLaboratories()
.pipe(
switchMap(outerResp => {
const total = outerResp.headers.get(outerResp.headers.get('total'));
return this.checkinService.getGenCoreLabs(total);
}),
take(1)
)
.subscribe(resp => {
this.apiResponse = resp;
this.areaList = this.apiResponse.map(labName => {
return labName.Name;
});
this.areaListIds = this.apiResponse.map(labGuid => {
return labGuid.Guid;
});
});
}
在我的component.ts文件中上面的代码中,单个take(1)足以取消订阅相关的http服务吗?还是我也必须在service.ts文件的第二个服务(getGenCoreLabs)中调用take(1)? (请参阅下面的代码以供参考)
-Service.ts-
public getGenCoreLabs(total: number): Observable<CoreLaboratoryData> {
const url = `/core/laboratories?per-page=${total}`;
return this.httpService.get(url).pipe(take(1));
}