rxjs - 当observable开始执行时执行某些操作

Ler*_*ner 4 rxjs angular

有没有办法在observable开始执行时附加一个处理程序(有人在其上调用subscribe)?

喜欢角度:

    this.http.post('someUrl', resource).pipe(
       catchError(),
       finalize((() => this.hideLoader()),
       **executing(() => this.showLoader()) <------**
    )
Run Code Online (Sandbox Code Playgroud)

car*_*ant 11

defer观察的工厂函数是最有可能你在找什么:

import { defer } from 'rxjs';

const post = defer(() => {
  this.showLoader();
  return this.http.post('someUrl', resource).pipe(
    catchError(),
    finalize(() => this.hideLoader())
  );
});
post.subscribe();
Run Code Online (Sandbox Code Playgroud)