How to read JSON object in Angular v18 template file with unknown key

Discussão em 'Angular' iniciado por Chandan Prakash Sharma, Dezembro 11, 2024.

  1. I am trying to read a JSON object containing list of unknown key in my template file (HTML) using Angular v18. But getting error stating Type 'JSON' is not assignable to Record<string, string | ((text: string, reviver?: ...)

    {
    "data": [
    {
    "col1": "val1",
    "col2": "val2",
    ..... // 100s of entries
    },
    {
    "col1": "val1",
    "col2": "val2",
    ..... // 100s of entries
    }
    ]
    }


    Below is my sample code to read the data in template file (HTML)

    @if(resp && resp.data) {
    @for(row of resp.data; track $index) {
    <tr *ngFor="let obj if row | keyvalue ">
    <td>{{obj.value}}</td>
    </tr>
    }
    }


    This line where I mentioned "let obj if row" is giving error stating row is


    row: Type 'JSON' is not assignable to Record<string, string | ((text: string, reviver?: ...)
    ​

    Tried few other approaches as well. But nothing seems working.

    Continue reading...

Compartilhe esta Página