how to display json array in angular 2 typescript front end by *ngFor

后端 未结 2 974
礼貌的吻别
礼貌的吻别 2021-01-27 23:43

Below is angular2 simple front end page::

       
title
相关标签:
2条回答
  • 2021-01-28 00:13

    Html code::

    <tr *ngFor="let notes of notes; let i = index">
        <td>{{notes.title}}</td>
        <td>{{notes.body}}</td>
    </tr>
    

    i just did this.notes=JSON.parse(data._body); and worked remaining code is as above.

    data => {
        console.log(data._body);
        this.notes=JSON.parse(data._body); // parsing here
        console.log("notes array"+this.title);
        console.log("Title :: "+this.notes.title);
    },
    
    0 讨论(0)
  • 2021-01-28 00:30

    You need to use notes instead of Note

    <tr *ngFor="let note of notes">
        <td>{{note?.title}}</td>
        <td>{{note?.body}}</td>
    </tr>
    

    DEMO

    0 讨论(0)
提交回复
热议问题