I have a component which has a dropdown. Based on what's selected in dropdown - the component displays additional information, by issuing another HTTP request.
If nothing is selected (first time component is displayed), then component should selected first one from the list
I have tried to subscribe to API response, but then I need to make nested API call, which I know is a bad practice...
ngOnInit() {
this.myService.getSelectedUnit(this.id).subscribe(selectedUnit => {
this.myService.getAllUnits().subscribe(units => {
if (!selectedUnit) {
selectedUnit = units[0];
}
this.myService.getUnitData(selectedUnit).subscribe(data => {
this.data = data;
});
});
});
}
I would like to avoid nesting the api calls and integrate it into one observable sequence.