【问题标题】:How to get data from second stream by first?如何首先从第二个流中获取数据?
【发布时间】:2021-12-01 02:31:24
【问题描述】:

我试图从 BehSubject this.visible$ 获取数据,仅在 this.redraw$ 发生时。

它有效,但如果 this.visible$ 在某处更改,则上一个流再次有效。如何避免?

this.redraw$.pipe(mergeMap(() => this.visible$)).subscribe((userfavourite: UserFavourite[]) => {}

作为解决方案,我可以这样做:

this.redraw$.subcribe(() => {
   this.visible$.subscribe((userfavourite: UserFavourite[]) => {}
});

【问题讨论】:

  • 不明白It works, but if the this.visible$ is changed somewhere the prev stream again works.是什么意思

标签: angular rxjs rxjs5


【解决方案1】:

可能是这样的:

this.redraw$.pipe(
  withLatestFrom(this.visible$),
  map(([_,v]) => v)
).subscribe(visible => {
  /* Do Something */
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 2014-06-07
    相关资源
    最近更新 更多