I\'ve created a demo (ng-run) where I have a button which invokes an Http request.
When the button is clicked, I invoke this method :
public getData
In service:
getData$ = this.http.get(API_ENDPOINT).pipe(shareReplay(1));
In component, need to unsubscribe and you can subscribe multiple times with single API call:
ngOninit(){ this.data$ = this._jokeService.getData$; this.data$.subscribe() }
In template, use:
*ngIf="data$ | async as data"