[英]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.