User 5842
User 5842

Reputation: 3029

Picking out individual items from an Observable array

If I have a method in a service in Angular that returns an Observable<MyModel[]>, how can I do something like this:

myService.myMethod().map(items => item)

In other words, how can I pick out each item in the items array and then do something with it?

Upvotes: 0

Views: 24

Answers (1)

Lazar Ljubenović
Lazar Ljubenović

Reputation: 19764

Your method returns an observable, which emits an array of items. So you want to transform that into a different stream. You're correctly suing your map here. Now, how do you want to transform each element from an array? Use map again, only this time it will come from Array prototype instead from Rx.Observable:

myService.myMethod().map(items => items.map(item => /* transform */))

Upvotes: 2

Related Questions