你能告诉我我在做什么错吗?
this.scheduleService.GetZones(environment.systemId)
.pipe(
mergeMap((zone: Zone) => {
return this.dashboardService.GetLatestMeasurementValue(environment.systemId, zone.sensorId)
})
.subscribe(mois => {
this.currentMoisture = mois;
})
);
}
我收到此错误:类型'OperatorFunction'不存在属性'subscribe'
答案 0 :(得分:3)
您无法订阅运营商。您需要进行以下订阅。
this.scheduleService.GetZones(environment.systemId)
.pipe(
mergeMap((zone: Zone) => {
return this.dashboardService.GetLatestMeasurementValue(environment.systemId, zone.sensorId);
})
)
.subscribe(mois => {
this.currentMoisture = mois;
})
答案 1 :(得分:0)
我看到我们正在通过该方法名称GetLatestMeasurementValue
将区域值映射到最新的度量值。
如果您始终对最新值感兴趣,switchMap是更好的运算符
this.scheduleService.GetZones(environment.systemId)
.pipe(
switchMap((zone: Zone) => {
return this.dashboardService.GetLatestMeasurementValue(environment.systemId, zone.sensorId);
})
)
.subscribe(mois => {
this.currentMoisture = mois;
})
如果这是一次事件,那么简单的map
也可以完成以下工作:
this.scheduleService.GetZones(environment.systemId)
.pipe(
map((zone: Zone) => {
return this.dashboardService.GetLatestMeasurementValue(environment.systemId, zone.sensorId);
})
)
.subscribe(mois => {
this.currentMoisture = mois;
})