I have this working code. It fetches the ID from the router and applies it as a parameter to get load in the data for the component.
this.route.params.subscribe(_ => {
this.id = _.id;
this.service.getMineral(this.id)
.subscribe(suc => this.data = suc, err => console.log(err));
}
);
Then, I tried to play around with better approaches and want to invoke the second subscription when the first one completes. According to the second sample in this answer, I'm supposed to share the first result and then switch map to unsubscribe from it and proceed with the next one. So I implemented the following.
const route$ = this.route.params.pipe(share());
const data$ = route$.pipe(
switchMap(() => this.service.getMineral(this.id)));
route$.subscribe(_ => this.id = _.id);
data$.subscribe(suc => this.data = suc, err => console.log(err));
Regrettably, this makes no call to the server and no data is delivered to the client. After trying several alterations, I gave up, due to lack of ideas.
What's the significant difference between those two approaches? Where do I get confused on my interpretation of the second sample?