I have the following code in the service layer and I have two questions:
return this.equipmentService.getEquipment(this.id) //returns subscription
.subscribe((equipment : Equipment) =>
{
this.getEquipmentTags(); //returns subscription
this.getPredictions(); //returns subscription
});
});
Do not fire the subscription too early, as @igor point out and you (this.equipmentService.getEquipment(this.id)
do not returns a subscription, it returns an Observable, because in other way you cannot subscribe to it), use concatMap
(and pipeable operators) to get chained you Observables.
getChainedObservables() {
return this.equipmentService.getEquipment(this.id)
.pipe(
concatMap((equipment : Equipment) => this.getEquipmentTags()),
concatMap(() => this.getPredictions())
);
}
then call it,
this.getChainedObservables().subscribe(console.log);