I use shareReplay to call only once (like a cache) a webservice to retrieve some informations :
In my service :
getProf
The other answers are all fine, but rather than having to reset the actual shareReplayed observable, a simpler approach might just be caching the result like so:
protected profile$: Observable;
getProfile$(): Observable {
if (!this.profile$) {
this.profile$ = this.callWS().pipe(shareReplay(1));
}
return this.profile$;
}
resetProfile() {
this.profile$ = null;
}
ref: https://blog.angularindepth.com/fastest-way-to-cache-for-lazy-developers-angular-with-rxjs-444a198ed6a6