Sun*_*mar 21 rxjs angular angular6 rxjs6
我正在使用RXJS 5,现在当我升级到6时,我遇到了一些问题.
以前我能够使用catch和最后但是根据更新catch用catchError替换(在管道中)现在如何使用finally?
我也有一些问题:
我是否需要更改throw-> throwError(在下面的代码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);
//});
);
Run Code Online (Sandbox Code Playgroud)
另外如何使用publish().refCount()?
mar*_*tin 30
使用throwError而不是Observable.throw,请参阅https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#observable-classes
finally被重命名为finalize,你将pipe()在其他运营商中使用它.
与publish()和相同refCount().两者都是你将在里面使用的运营商pipe().
20B*_*0B2 21
需要从rxjs /运算符导入finalize
finalize
然后在里面使用finalize rxjs/operators,
observable()
.pipe(
finalize(() => {
// Your code Here
})
)
.subscribe();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14532 次 |
| 最近记录: |