I would like to call an http request which must return an observable which is then subscribed by a method which is called with specific time interval for further ...
Please consider this
Subscriber method
startReceivingMeasurmentLiveDataV2(httpOptions: any,deviceId:number,seriesType:string,aggregation:string,from:string,to:string,pageSize:number,revert:boolean) {
debugger;
if (this.intervalSubscription) {
this.intervalSubscription.unsubscribe();
}
this.intervalSubscription = interval(200)
.pipe(
takeWhile(() => this.alive),
// switchMap(() => this.deviceService.getMeasurmentLiveUpdateCardDataV2(httpOptions,deviceId,seriesType,aggregation,from,to,pageSize,revert)),
switchMap(() => this.deviceService.GetMeasurmentsV2(httpOptions,deviceId,seriesType,aggregation,from,to,pageSize,revert)),
)
.subscribe((liveUpdateChartData: any[]) => {
debugger;
this.liveUpdateChartData = [...liveUpdateChartData];
//console.log("measurment data"); // console.log(this.liveUpdateChartData); }); }
Http Observable
GetMeasurmentsV2(httpOptions: any, deviceID: number, seriesType: string, aggregationType: string, dateFrom: string, dateTo: string, pageSize: number, revert: boolean): Observable<any[]> {
let url = `${this.config.apiUrl}/measurement/measurements/series?aggregationType='${aggregationType}'&dateFrom='${dateFrom}'&dateTo='${dateTo}'&pageSize='${pageSize}'&revert='${revert}'&series='${seriesType}'&source='${deviceID}'`
url = url.replace(/'/g,'');
return this.httpClient.get<any>(
url
,httpOptions)
.pipe(map(measurments => {
return observableOf(measurments);
}));
}
Now here is the issue
Please help me how can I fix this?
You're returning a nested observable right now
just return the initial observable return this.httpClient.get<any>(url, httpOptions)
, without wrapping the response in another observable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.