我有一个Observable。如果成功,我想给用户反馈,然后刷新页面上的数据。所以我所做的就是调用do
运算符来获取用户反馈,然后调用forkJoin
来刷新数据。问题是,forkJoin
之后无法拨打do
并出现以下错误:Error:(37, 12) TS2339: Property 'forkJoin' does not exist on type 'Observable<void>'.
代码:
this.pickService.activate(event)
.do(() => this.snackBar.open(`Pick activated`, null, {duration: 5000}))
.forkJoin([
this.pickService.get('DRAFT', 'dt,asc'),
this.pickService.get('PENDING', 'dt,desc')
])
.subscribe(results => {
this.draftPicks = results[0];
this.pendingPicks = results[1];
});
The Observable
activate(id: string): Observable<void> {
return this.http.patch<void>(`/api/v1/picks/${id}`, {status: 'PENDING'});
}
答案 0 :(得分:2)
forkJoin
是静态创建方法,不是运营商可以链。所以你只能Observable.forkJoin
。
答案 1 :(得分:1)
forkJoin只是一个可观察的创建方法。所以我认为你想要做的就是这样:
let requests = [ this.pickService.get('DRAFT', 'dt,asc'),
this.pickService.get('PENDING', 'dt,desc') ];
this.pickService.activate(event)
.do(() => this.snackBar.open(`Pick activated`, null, {duration: 5000}))
.switchMap(a => Observable.forkJoin(requests))
.subscribe(...)