I have a service with a function of type
getSummary(id: string, universe: string): Observable<INTsummary[]>
When I call this I only ever want the first item in the INTsummary[]
, so I'm trying to use rxjs first
operator to do this:
loadQuickSummary(){
var obj = this.myService.getSummary(this.user.id, this.user.universe).first();
console.log("getting quick summary");
obj.subscribe(r => {
console.log(`first value ${JSON.stringify(r)}`)
})
}
from reading docs and stackoverflow, this should return an object, but instead I get back an array of INTsummary
's .
How can I get back just the first object in the INTsummary[]
array?
Observable.first
gives you the first value of the stream of values, not of the array that is one of those values. You need to do that inside aObservable.map
, where you have that array ->this.myService.getSummary(...).map(arr => arr[0])...
.