My problem is to combine two consecutive observables and return it as a single observable. There are a lot of combine operators in rxjs but documentation just confused me.
Here is a working solution I came up with. However, I feel like it isn't the right way to do it for readability.
const observableGetId = () => {SomeFunctionBody};
const observableGetDataWithId = (id) => {SomeAnotherFunctionBody};
observableGetId.pipe(
mergeMap((id) => {
return forkJoin([
of(id),
observableGetDataWithId(id)
])
})
).subscribe((result) => {
console.log(result[0]) // id
console.log(result[1]) // data
})
Is there a better operator or some other way to do this?