I am trying to print an http respone to a mat table. I have problem to format the data to an array and set it to mat-datasource. can someone please guide me.
[
{
"n1":"abcd",
"n2":"abcde",
"A1":
{
"A11":{"t":b1},
"A12":{"t1":b2},
"A13":{"t":b3},
"A14":{"t":b4},
"A15":{"t":b5}}
},
{
"n2":"bcde",
"n2":"bcdef",
"A1":
{
"A11":{"t":b1,"t1":b2},
"A12":{"t":b3},
"A13":{"t":b4},
"A14":{"t":b5},
"A15":{"t":b6}
}
}
}
]
Mat table should look like this.
---------------------------------------------------
| data | A11 | A12 |A13 | A14 | A15 |
---------------------------------------------------
| n1,n2 | t | t | t | t | t |
---------------------------------------------------
| n1,n2 | t | t | t | t | t |
---------------------------------------------------
i have tried below but unable to set the sub values(A11, A12, A13, A14, A15) to an array
ngOnInit() {
this.gService.getlist().subscribe(
(res: any[]) => {
let GL = new Array();
res.forEach(gl => {
GL.push({
n1: gl.n1,
n2: gl.n2,
A1: gl.A1,
// unable to read other json values part of A1.
})
})
this.datasource.data = GL;
}
````
gl.A1.A11.torgl.A1["A11"]["t"]??