我基本上需要给我的 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);
}
现在我试图将其浓缩为一个方法,所以我尝试了这个
我正在像这样导入 rxjs
import { combineLatest } from 'rxjs';
import { tap, filter } from 'rxjs/operators';
这是我的方法
getStoreData() {
combineLatest(
this._store.select('userInfo'),
this._store.select('cats'),
this._store.select('dogs')
).pipe(tap(([userInfo, cats, dogs]) => console.log(userInfo, cats, dogs));
}
我像这样调用我的方法
ngOninit() {
this.getStoreData()
}
我的问题是正在调用该方法,但我从未获得控制台日志?
我不确定我做错了什么
编辑
我也试过
getStoreData {
forkJoin(
this._store.pipe(select('userInfo')),
this._store.pipe(select('xberts')),
this._store.pipe(select('tasks'))
).subscribe(res => console.log(res));
}
但还是同样的问题,没有
console.log()
任何帮助,将不胜感激!
最佳答案
我认为你需要订阅。试试这个:
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()
}
或者
ngOninit() {
this.getStoreData().subscribe()
}
关于angular - 将多个 ngrx 存储选择合并为单个调用 Angular 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55527943/