I have a function getNews()
, which basically returns angular's http.get request. Result of request is array of Id's. I would like to iterate through this array I got and run another http.get request (function getItem(id)
), which will then return single Id's object, received from server.
I've tried using it like so:
getLatest() {
return this.http.get('all_news_url')
.map(res => res.json())
// I even tried creating Observable from array and get only 5 elements
//.map(res => Observable.from(res.json()))
//.take(5)
.map((data) => this.getItem(data))
.subscribe(
data => {
console.log(data);
}
)
}
getItem(itemId: any): Observable<any> {
console.log('item id', itemId);
return this.http.get(this.generateUrl(`item/${itemId}`))
.map(res => res.json());
}
Obviously, this doesn't work. parameter to getItem()
function always gets passed as whole array of Id's.
Thank you everyone for participating in this question.