I have this JSON:
{
"mainObjeto": {
"id": 1,
"descripcion": "some text",
"reclamoMotivo": {
"id": 3,
"nombre": "yyyyy",
"descripcion": "Producto con Defectos"
},
"empresa": {
"id": 1,
"nombreEmpresa": "xxxx",
"descripcionEmpresa": "xxxx"
},
"adjuntos": [
{
"id": 1,
"nombreAdjunto": "test.txt"
},
{
"id": 2,
"nombreAdjunto": "prueba.jpeg"
}
],
"fechaCreacion": "2024-10-06T18:22:55.202+00:00",
"correoCliente": "[email protected]",
"reclamoEstado": {
"id": 1,
"reclamoEstadoMaestro": {
"id": 2,
"nombreEstado": "EN_REVISION",
"descripcion": "En revisión"
},
"commentSupport": "falla sistema",
"updatedAt": "2024-10-06T18:22:55.315+00:00",
"correoAsesor": "[email protected]"
}
}
}
I need to populate the values in a grid using angular, for testing purposes I tried to get the data with:
<div class="bank" *ngFor="let item of list">
<p *ngFor="let itemAux of item | keyvalue">
Key: <b>{{itemAux.key}},</b> value: <b> {{itemAux.value}} |</b>
</p>
</div>
this is my ts code:
ngOnInit(): void {
this.service.getData()
.subscribe( data => { this.objs = data });
}
but I get this value:
Key: mainObjeto, value: [object Object]
Please your help
3
Answers
Try accessing the value of
mainObjeto
, since it contains the properties that you want to iterate. I am also usingjson
pipe to view the contents of complex objects.To use the
json
pipe in HTML, make sure you import eitherCommonModule
orJsonPipe
to theimports
array of the standalone component or module.You need to flatten the nested object structure before displaying it. This can be done in your component by extracting the relevant fields.
Now, create a grid to display the flattened data. You can use a simple table for this:
You can directly access the properties of mainObjeto and its nested objects.
In your HTML template, you can access the nested properties directly