简体   繁体   中英

pull first object from ngrx/store in Angular2

if I have an ngrx store that consists of preferences with a sample looking like:

preferences: [{ name: 'pref1', type: 'boolean', value: true }, { name: 'pref2', type: 'boolean', value: true }, ... ]

how would I grab just the first stored preference as an observable chaining off this._store.select('preferences') ?

I can't find the correct syntax, although I know rxjs has a .first() method available. I haven't been able to find a good example of what I'm looking for to make it work.

This should do it:

this._store.select('preferences')
  .filter((value, index) => index === 0)

The answer @Sasxa gave was almost exactly right. This is the solution I used to get it working:

this._store.select('preferences') .map(preferences => preferences.filter((value, index) => index === 0))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM