I am receiving a nested response back from a server in my Angular app. I need to access the data inside, but there are several responses contained within one parent object. So far I have been able to drill inside somewhat, but I am having trouble getting in further.
So far I have this code:
getPlants(): Observable<any> {
const headers = { headers: this.headers };
return this.httpClient.get(`${this.requestUrl}, headers);
}
This gets the data in question. Next, I have the function where I am having issues.
destructurePlants() {
this.getPlants().subscribe(data => {
const plants = Object.keys(data).map(e => data[e]);
plants.forEach(plant => {
console.log(plant);
});
}
The data I am getting back comes back like this.
{
"plantMap": {
"1": {
"PLANTTYPE1": {
"id": "1",
"style": "plantStyle",
"styleDesc": "Luxurious green",
"codeId": "1"
},
"PLANTTYPE2": {
"id": "1",
"style": "plantStyle2",
"styleDesc": "Luxurious red",
"codeId": "2"
},
"PLANTTYPE3": {
"id": "1",
"style": "plantStyle3",
"styleDesc": "Luxurious succulent",
"codeId": "3"
},
"2": {
"TREE1": {
"id": "2",
"style":"plantStyle",
"styleDesc":"Oak",
"codeId": "1"
},
"TREE2": {
"id": "2",
"style": "plantStyle2",
"styleDesc": "Evergreen",
"codeId": "2"
},
"TREE3": {
"id": "2",
"style": "plantStyle3",
"styleDesc": "Myrtle",
"codeId": "3"
}
}
}
}
Ideally, I would like to be able to grab each 1, 2, etc and then drill down further into PLANTTYPE AND TREETYPE objects, etc.