订阅多个可观察项,条件匹配后仅获得一个

时间:2019-04-25 09:32:44

标签: angular rxjs angular7 rxjs6

我有一个可观察的物品阵列和一个可观察的物品。我想同时订阅两者,并从可观察项数组中获得可观察项的索引

我已经尝试过switchmap,concatmap和mergemap,但没有得到任何结果

selectedcategory$ = this.store.pipe(select(selectSelectedCategory));
```observable of array of items
allcategories$ = this.store.pipe(select(selectCategories));

```i am working with ngrx 

I an expecting index of item

1 个答案:

答案 0 :(得分:2)

import { combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';

...

combineLatest(
  selectedcategory$,
  allcategories$,
).pipe(
  map(([selected, categories]) => categories.findIndex(/* whatever logic you need */),
).subscribe(...);