I need to prevent multiple api calls to certain routes.
I keep hearing that I should use shareReplay()
to prevent multiple api calls especially when you are going between pages and coming back to the same page. I ve used shareReplay()
but when I look at the network tab it keeps on making the network request. Any ideas? I ve made a stackblitz link here = https://stackblitz.com/edit/angular-ivy-jadosn
页: 1 法典:
getWaterPokemon(): Observable<Filter[]> {
return this.http.get<Filter[]>(`${this.getApi()}/type/5`, { responseType: json }).pipe(
map((clients: any) => clients.pokemon.map((client: any) => client.pokemon)),
shareReplay()
);
}
这里是我的<条码>水。 法典:
ngOnInit(): void {
this.waterPokemon$ = this.httpService.getWaterPokemon().pipe(
shareReplay()
);
}
每当你进入“水 P”网页时,就会看到该网络的要求发生。