I have an observable, to which I subscribe and I do some operations on the result value (a reduce()
and a map()
).
But inside that observable I would like to call another observable that just returns a number, and I need that number in my map()
.
Here an example:
this.getYearlyDataByIdAndYear(292, 2019).subscribe(result = > {
let ferienSaldo: FerienSaldo;
this.getVacationsYearlyDataByIdAndYear(292, 2019).subscribe(result = > {
// this is my inner observable and I need to save this result, and use it below!
ferienSaldo = result;
});
this.yearlyOverview = result.reduce < Array < YearlyOverview >> ((prev, current, i, all) = > {
// some code that is not important
let overviewVar: YearlyOverview = {
saldo: ferienSaldo.value
};
prev.push(newTLOverview);
}
return prev;
}, new Array < YearlyOverview > ())
});
basically as you can see, inside my initial Observable, I will need the value from the inner one, and I will copy that value inside my reduce()
to assign it to a new object I'm creating!
The issue with my code is, the "let ferienSaldo" variable cannot be accessed inside the second observable, and besides that I'm sure there is a better way to combine this!