Search code examples
rxjsangular5rxjs5rxjs-pipeable-operators

How can I pass the output of an http call as input to another http call in Rx JS?


Hi I am getting an error when i tries to do the following operation

export class FlightFormTemplatesStepComponent
{

 tagonMessagePrefix: TagOnMessagePrefix;


  ngOnInit() {
     this.flightService.get(this.flightId).pipe(
         tap (flight => {this.flight = flight}),
         mergeMap( (flight) => {
           return this.flightService.getTagonMessagePrefix(flight);
         })
        ).subscribe(
          (tagonMessagePrefix) => { this.tagonMessagePrefix = tagonMessagePrefix}

        );
   }
}

this is the error I am recieving.

property) FlightFormTemplatesStepComponent.tagonMessagePrefix: TagOnMessagePrefix
Type '{}' is missing the following properties from type 'TagOnMessagePrefix': id, flightName, flightTagonTypes, configuredGlobalTagonSettings, tagonTextts(2739)

Any idea how can i fix this issue


Solution

  • I changed to map operation and it works

    this.flightService.get(this.flightId).pipe(
     tap (flight => {this.flight = flight}),
     switchMap( (flight) => {
       return this.flightService.getTagonMessagePrefix(flight);
     })
    ).subscribe(
      (tagonMessagePrefix:TagonMessagePrefix) => { this.tagonMessagePrefix = tagonMessagePrefix}
    
    );