I have service like this :
getLastStatus(id): Observable<string> {
let url_detail = this.apiurl + `/${id}`;
return this.http.get<any>(url_detail, this.httpOptions).pipe(
map(data => {
var status = data['data'].reduce((item, curr) => {
return item.id < curr.id ? curr : item;
}).status.title;
return status;
}),
catchError(this.handleError)
);
}
getData(){
return this.http.get<DataModel[]>(this.apiurl, this.httpOptions).pipe(
tap(data=> {
data.map(d=>{
this.getLastStatus(d.id).subscribe(s=>{
d.status = s;
});
});
}),
catchError(this.handleError)
);
}
I want to update value of status from the result of json object. But, when I subscribe getData() like this, the value of status not updated.
this.myService.getData().subscribe(data=>{
console.log(data)
data.map(d=>{
console.log("status ", d.status) //value of status not updated
})
});
What's should i do with my code? Any suggestion?