Efficiently get Observable of an array BehaviorSubjects

[亡魂溺海] 提交于 2019-12-13 16:28:33

问题


I have this field:

smartArray: BehaviorSubject<BehaviorSubject<object>[]>; 
//Example
[{key1: 'value1', key2: value2},...]; 

I now want to get and subscribe to one of the properties:

getObeservablePropertyOfSmartArray(index, property){
   return this.smartArray.pipe(
         //...getelementAtIndex <---dont know how
         //lets say the elementatIndex is elem: 
         elem.pipe(
         //get the property and return the Observable

         )).asObservable(); 
}

So I basically need the equivalent of array[index] and object[key] and return Obeservable for BehaviorSubjects. How can I do that?


回答1:


you can use mergeMap to switch to that observable on the index, then you can use map to get the property value that you want I made example for you here: https://stackblitz.com/edit/angular-qzeuzt



来源:https://stackoverflow.com/questions/57754817/efficiently-get-observable-of-an-array-behaviorsubjects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!