Angular:如何使用RXJS 6调用finally()

前端之家收集整理的这篇文章主要介绍了Angular:如何使用RXJS 6调用finally()前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用RXJS 5,现在当我升级到6时,我遇到了一些问题.

以前我能够使用catch和最后但是根据更新catch用catchError替换(在管道中)现在如何使用finally?

我也有一些问题:

我是否需要更改throw-> throwError(在下面的代码Observable.throw(err);)

  1. import { Observable,Subject,EMPTY,throwError } from "rxjs";
  2. import { catchError } from 'rxjs/operators';
  3.  
  4. return next.handle(clonedreq).pipe(
  5. catchError((err: HttpErrorResponse) => {
  6. if ((err.status == 400) || (err.status == 401)) {
  7. this.interceptorRedirectService.getInterceptedSource().next(err.status);
  8. return Observable.empty();
  9. } else {
  10. return Observable.throw(err);
  11. }
  12. })
  13. //,finally(() => {
  14. // this.globalEventsManager.showLoader.emit(false);
  15. //});
  16. );

另外如何使用publish().refCount()?

>使用throwError而不是Observable.throw,请参阅 https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#observable-classes >最后重命名为finalize,你将在其他运算符中使用pipe(). >与publish()和refCount()相同.两者都是你将在pipe()中使用的运算符.

猜你在找的Angularjs相关文章