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 和 finally 但随着更新 catch 被 catchError 替换(在管道中)现在如何使用 finally?
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
,参见 https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#可观察类finally
已重命名为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屋!