簡體   English   中英

從ngrx /存儲在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM