Reputation: 21
I've two oberservables in my typescript:
ob_oj
and ob_oj2
.
I concat the two observables like this:
Observable.concat(ob_oj,ob_oj2).subscribe(res=>{this.detailSatz=res;})
detailSatz
is an Array from type any - I want to access to both results of ob_oj
and ob_oj2
via detailSatz
in my HTML. But the results in the Array detailSatz
were overrided, so I only get the results of ob_oj2
.
What am I doing wrong here? Is there a solution for a multiple number of observables? (An Array of observables)
Thanks in advance.
Upvotes: 1
Views: 610
Reputation: 659
You can use forkJoin and is best used when you have a group of observables and only care about the final emitted value of each. Try something like
var result = forkJoin([ob_oj, ob_oj2]).subscribe(
result => console.log(result)
// result[0] is ob_oj
// result[1] is ob_oj2
)
Refer documentation: https://www.learnrxjs.io/operators/combination/forkjoin.html
Upvotes: 1