Angular2: I want to use the result of .subscribe()
in a consequent observable.
This is in order to use the id from the parent subscribe in the nested subscribe.
I've tried using .switchMap()
first, but this doesn't seem to work.
This is my attempt:
this.serviceA.getOrg()
.switchMap(org => this.serviceB.getOrgType(org.id))
.subscribe(type => {
console.log(type);
});
Try flatMap:
this.serviceA.getOrg()
.flatMap(org => this.serviceB.getOrgType(org.id))
.subscribe(type=> {
console.log(type);
});
try like this :
this.serviceA.getOrg()
.flatMap((org) => {
console.log('org', org);
return this.serviceB.getOrgType(org.id)
})
.subscribe((type) => {
console.log('type', type);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With