问题
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