If you call every time this.http.get(API_ENDPOINT).pipe(shareReplay(1))
, each time http request will be triggered. If you want to make http call once and cache data, the following is recommended.
You first get the observable for data:
ngOninit(){
this.data$ = this._jokeService.getData().pipe(shareReplay(1));
}
Now subscribe multiple times:
public getData(){
this.data$.subscribe();
}
Your service:
public getData() {
return this.http.get(API_ENDPOINT)
}