![](/img/trans.png)
[英]pull objects with a matching attribute from ngrx/store in Angular2
[英]pull first object from ngrx/store in Angular2
如果我有一個由首選項組成的ngrx
存儲,其樣本如下所示:
preferences: [{ name: 'pref1', type: 'boolean', value: true }, { name: 'pref2', type: 'boolean', value: true }, ... ]
我將如何僅將第一個存儲的首選項作為可觀察到的鏈接this._store.select('preferences')
?
盡管我知道rxjs
具有可用的rxjs
.first()
方法,但是我找不到正確的語法。 我一直無法找到一個很好的例子來說明我正在使它起作用。
應該這樣做:
this._store.select('preferences')
.filter((value, index) => index === 0)
@Sasxa給出的答案幾乎完全正確。 這是我用來使其工作的解決方案:
this._store.select('preferences') .map(preferences => preferences.filter((value, index) => index === 0))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.