To ensure that each subscription to an HTTP observable triggers a new HTTP call, it is recommended to set a flag outside of the pipe operation as shown in this example.
fetchData(){
isLoading=true;
return this.http.makeRequest().pipe(finalize(()=>isLoading=false));
}
If you are interested in tracking the subscriber count (which always resets to 0 after each request due to finalization of the HTTP observable), consider exploring the implementation of refCount() and share() operators which internally manage subscriber counts.
Edit:
You can streamline the process of setting the flag by using a dummy observable as an entry point, like so:
fetchData(){
return of(null).pipe(
tap(()=>isLoading=true),
switchMapTo(this.http.makeRequest()),
finalize(()=>isLoading=false)
)
}