将多个 ngrx 存储选择合并为单个调用 Angular 7

Smo*_*son 4 rxjs typescript angular

我基本上需要给我的ngrx商店打3 次电话

所以我所拥有的是

getUserInfo() {
    this._store.select('userInfo')
       .subscribe(result => this.userInfo = result);
}

getCats() {
    this._store.select('cats')
       .subscribe(result => this.cats = result);
}

getDogs() {
    this._store.select('dogs')
        .subscribe(result => this.dogs = result);
}
Run Code Online (Sandbox Code Playgroud)

现在我试图将其浓缩为一个方法,所以我尝试了这个

我正在像这样导入 rxjs

import { combineLatest } from 'rxjs';
import { tap, filter } from 'rxjs/operators';
Run Code Online (Sandbox Code Playgroud)

这是我的方法

getStoreData() {
    combineLatest(
        this._store.select('userInfo'),
        this._store.select('cats'),
        this._store.select('dogs')
    ).pipe(tap(([userInfo, cats, dogs]) => console.log(userInfo, cats, dogs));
}
Run Code Online (Sandbox Code Playgroud)

我像这样调用我的方法

ngOninit() {
   this.getStoreData()
}
Run Code Online (Sandbox Code Playgroud)

我的问题是正在调用该方法,但我从未获得控制台日志?

我不确定我做错了什么

编辑

我也试过

getStoreData {
    forkJoin(
      this._store.pipe(select('userInfo')),
      this._store.pipe(select('xberts')),
      this._store.pipe(select('tasks'))
    ).subscribe(res => console.log(res));
}
Run Code Online (Sandbox Code Playgroud)

但仍然是同样的问题,没有 console.log()

任何帮助,将不胜感激!

del*_*hum 5

我认为你需要订阅。试试这个:

getStoreData() {
    combineLatest(
        this._store.select('userInfo'),
        this._store.select('cats'),
        this._store.select('dogs')
    ).pipe(filter(e => !e.includes(null)),tap(([userInfo, cats, dogs]) => console.log(userInfo, cats, dogs))
    .subscribe()
}
Run Code Online (Sandbox Code Playgroud)

或者

ngOninit() {
   this.getStoreData().subscribe()
}
Run Code Online (Sandbox Code Playgroud)