Angular 将.withLatestFrom与单个可观察值合并

Angular 将.withLatestFrom与单个可观察值合并,angular,ngrx-store,Angular,Ngrx Store,在ngrx/store Angular应用程序中,我需要在一个地方强制执行操作,我需要从store中获取最新的值并进一步传递 我需要以某种方式使用。withLatestFrom(),因为我知道这不是一个静态方法 所以我想我应该将.withLatestFrom()操作符与一个简单的可观察的.of(null)结合起来。但这不起作用。我真的不知道为什么 因此,这将起作用: Observable.of(null) .do(val => console.log('value', val))

在ngrx/store Angular应用程序中,我需要在一个地方强制执行操作,我需要从store中获取最新的值并进一步传递

我需要以某种方式使用
。withLatestFrom()
,因为我知道这不是一个静态方法

所以我想我应该将
.withLatestFrom()
操作符与一个简单的
可观察的.of(null)
结合起来。但这不起作用。我真的不知道为什么

因此,这将起作用:

Observable.of(null)
  .do(val => console.log('value', val))
  .subscribe();
但结合起来不会:

Observable.of(null)
  .withLatestFrom(this.myStoreValues$)
  .do(args => console.log('with', args))
  .subscribe();

有解决方法吗?

CombineTest操作员应该会帮助您。本质上,当发生变化时,它将来自多个源的输出流化。在您的情况下,您唯一的流可以如下组合

Observable.combineLatest(this.myStoreValues$)
.do(args => console.log('with', args))
  .subscribe();

CombineTest操作员应该会帮助您。本质上,当发生变化时,它将来自多个源的输出流化。在您的情况下,您唯一的流可以如下组合

Observable.combineLatest(this.myStoreValues$)
.do(args => console.log('with', args))
  .subscribe();

什么是
this.myStoreValues$
?“我需要在一个地方强制行动…”为什么?它是从存储选择器创建的一个可观察对象,如:
this.myStoreValues=this.store.select(getMyStoreValues)
我刚刚发现它上面有
.share()
,当我删除
.share()
时,代码开始工作。不太明白。这是什么。myStoreValues$?“我需要在一个地方强制行动…”为什么?它是从存储选择器创建的一个可观察对象,如:
this.myStoreValues=this.store.select(getMyStoreValues)
我刚刚发现它上面有
.share()
,当我删除
.share()时
代码开始工作。我不太明白。