1

Can you tell me what am I doing wrong ?

this.scheduleService.GetZones(environment.systemId)
  .pipe(
    mergeMap((zone: Zone) => {
      return this.dashboardService.GetLatestMeasurementValue(environment.systemId, zone.sensorId)
    })
    .subscribe(mois => {
      this.currentMoisture = mois;
    })
  );
}

I get this error: Property 'subscribe' does not exist on type 'OperatorFunction'

C.OG
  • 6,236
  • 3
  • 20
  • 38
Matei Emil
  • 65
  • 9

2 Answers2

3

You cannot subscribe to an operator. You need to subscribe as follows.

this.scheduleService.GetZones(environment.systemId)
    .pipe(
       mergeMap((zone: Zone) => {
          return this.dashboardService.GetLatestMeasurementValue(environment.systemId, zone.sensorId);
       })
     )
    .subscribe(mois => {
      this.currentMoisture = mois;
    })
C.OG
  • 6,236
  • 3
  • 20
  • 38
Anto Antony
  • 842
  • 6
  • 12
  • `mergeMap` will keep your `this.scheduleService.GetZones` observable alive. if your services work the way i think they do, i'd consider `switchMap` instead, this will make sure `this.scheduleService.GetZones` will get unsubscribed. – Stavm Dec 16 '19 at 12:15
0

I see we are mapping zone value to the latest measure value by this method name GetLatestMeasurementValue. If you are always interested in the latest value switchMap is a better operator

this.scheduleService.GetZones(environment.systemId)
    .pipe(
       switchMap((zone: Zone) => {
          return this.dashboardService.GetLatestMeasurementValue(environment.systemId, zone.sensorId);
       })
     )
    .subscribe(mois => {
      this.currentMoisture = mois;
    })

And if it is a single time event simple map would also do the job as below :

this.scheduleService.GetZones(environment.systemId)
    .pipe(
       map((zone: Zone) => {
          return this.dashboardService.GetLatestMeasurementValue(environment.systemId, zone.sensorId);
       })
     )
    .subscribe(mois => {
      this.currentMoisture = mois;
    })
Siddharth Pal
  • 1,408
  • 11
  • 23