I need to call a subscribe method within a subscribe method.
In the first subscribe method, it returns me a deviceid which is subsequently used in the second subscribe method.
result=[];
idArray=[2,4];
this.subscription =
this.quoteService.get(this.quoteid) //first api call
.subscribe((quote: Quote) => {
this.deviceid = quote["deviceid"];
this.faultService.get(this.deviceid) //second api call
.pipe(first())
.subscribe((faultGroup: FaultGroup[]) => {
faultGroup.forEach(({ faults }) => {
//execute logic for 2nd subscription
if (faults) {
faults
.filter(
({ id }) => this.idArray.indexOf(id) > -1,
)
.forEach(fault => this.result.push(fault.name));
}
//end of logic
});
});
subscription.unsubscribe();
}
});
Can someone teach me how to use flatMap/switchMap to avoid using a nested subscribe? Appreciate your help!
first()? a synchronous method ?