In a project I am working on, after obtaining a list of objects from an HTTP "get" request, one of the fields for each object is a string containing a status, "DEAD", "IDLE", etc. Is there any way to edit the structure of the object that comes in the list so it contains a few more fields based on that status value? For example, after the transformation each of the objects in the list would have the boolean fields isDead, isIdle, etc. Is this what the transformResponse() method in Angular does?
Asked
Active
Viewed 47 times
0
-
perhaps [this stack overflow question](https://stackoverflow.com/questions/18147126/angularjs-http-and-transformresponse) will shed some light – Jaromanda X Jun 28 '18 at 23:15
1 Answers
0
You can do something like this.
private getData(): void {
this.http.get('https://reqres.in/api/users?page=2').pipe(map((res: any) => {
return res.data;
})).subscribe((data) => {
this.data =data.map((item) => {
return {
id: item.id,
first_name: item.first_name,
last_name: item.last_name,
avatar: item.avatar,
age: 50
}
});
});
};
In here UI am requesting for a list of data and for each of the items in the list I am appending a age
attribute.
You can find a working example in here

Anuradha Gunasekara
- 6,553
- 2
- 27
- 37