Is there a way to detect the start of the subcription of a rxjs observable within the pipe?
I want to trigger a loading indicator when a http observable (destroyed when respone has been finalized) get subscribed.
Or do I have to create a wrapper observable for this action?
It depends on what RxJS version you're using. With RxJS < 7.3 you can use defer():
defer(() => {
  loadingFlag = true;
  return this.http.doyourrequest().pipe(
    finalize(() => loadingFlag = false),
  );
});
Since RxJS >= 7.3 you can use new event handlers for tap():
this.http.doyourrequest().pipe(
  tap({
    subscribe: () => loadingFlag = true,
    finalize: () => loadingFlag = false,
  }),
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With