--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;
});
});
}
In the code above inside my component.ts file, is a single take(1) enough to unsubscribe from the dependent http services? Or do i have to call take(1) inside the second service(getGenCoreLabs) in service.ts file as well? ( please see the below code for reference)
--Service.ts--
public getGenCoreLabs(total: number): Observable<CoreLaboratoryData> {
const url = `/core/laboratories?per-page=${total}`;
return this.httpService.get(url).pipe(take(1));
}