带有Observable的forkJoin <void>

时间:2018-01-10 21:38:04

标签: angular rxjs

我有一个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'});
  }

2 个答案:

答案 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(...)