I would to have a function which sends an http request to an endpoint giving the list of all items, and then sending a second request to get the first element on that list. The function should return the last item. I'm using the following code but the second http request is not working.
getFirstItem(): Observable<any> {
return this.getList().pipe(concatMap(value => this.getItem(value[0].id)));
}
Using Angular 7 and rxjs 6.4.0
Any help is appreciated.
Edit: When running the following snippet, the second console log never gets called
getFirstItem(): Observable<any> {
return this.getList().pipe(
tap(x => console.log(x)),
concatMap(value => this.getItem(value[0].id)),
tap(x => console.log(x)) // never called
}
You can use mergeMap