我想调用一个http请求,该请求必须返回一个observable,然后由 在特定时间间隔内调用进一步的方法...
请考虑这个
订户方法
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(“测量数据”); // console.log(this.liveUpdateChartData); }); }
可观察的
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);
}));
}
现在是问题所在
请帮助我如何解决此问题?
答案 0 :(得分:2)
您现在正在返回嵌套的可观察对象
只需返回初始可观察的return this.httpClient.get<any>(url, httpOptions)
,而无需将响应包装在另一个可观察的