Angular:如何使用RXJS 6调用finally() [英] Angular : how to call finally() with RXJS 6
问题描述
我正在使用RXJS 5,现在将其升级到6时,我遇到了一些问题.
I was using RXJS 5, now as I upgraded it to 6, I am facing some problems.
以前我能够使用catch并最终使用,但是由于每次更新catch都被catchError替换(管道中的with),现在如何最终使用?
Previously I was able to use catch and finally but as per update catch is replaced with catchError (with in the pipe) now how to use finally?
我还有一些问题:
我是否需要更改throw-> throwError(在下面的代码Observable.throw(err);中)
Do I need to change throw->throwError (in below code Observable.throw(err);)
import { Observable, Subject, EMPTY, throwError } from "rxjs";
import { catchError } from 'rxjs/operators';
return next.handle(clonedreq).pipe(
catchError((err: HttpErrorResponse) => {
if ((err.status == 400) || (err.status == 401)) {
this.interceptorRedirectService.getInterceptedSource().next(err.status);
return Observable.empty();
} else {
return Observable.throw(err);
}
})
//, finally(() => {
// this.globalEventsManager.showLoader.emit(false);
//});
);
还有现在如何使用publish().refCount()吗?
Also how to use publish().refCount() now ?
推荐答案
-
使用
throwError
而不是Observable.throw
,请参见use
throwError
instead ofObservable.throw
, see https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#observable-classesfinally
被重命名为finalize
,您将在其他运算符的pipe()
内部使用它.finally
was renamed tofinalize
and you'll use it insidepipe()
among other operators.与
publish()
和refCount()
相同.两者都是在pipe()
中使用的运算符.the same with
publish()
andrefCount()
. Both are operators you'll use insidepipe()
.这篇关于Angular:如何使用RXJS 6调用finally()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!