如何隐藏JSON对象(angular2)?

时间:2017-06-21 11:40:32

标签: angular

我对服务器的回答是这样的:

  {
    "message": " list received successfully",
    "success": "true",
    "data": {
    "_list": [{
      "id": "",
      "name": "",
      "image_url": null,
      "is_occupation": true
      },
      {
      "id": "",
      "name": "",
      "image_url": null,
      "is_occupation": true
      }
    ],
    "responseCode":"",
  }

如何在angular2中以列表(html)显示此数据?

1 个答案:

答案 0 :(得分:0)

@Component({
selector:'list',
template: `
<table>
    <thead>
        <th>id</th>
        <th>name</th>
        <th>image_url</th>
        <th>is_occupation</th>
    </thead>
    <tbody>
        <tr *ngFor="let data of responseData.data._list">
            <td>{{data.id}}</td>
            <td>{{data.name}}</td>
            <td>{{data.image_url}}</td>
            <td>{{data.is_occupation}}</td>
        </tr>
    </tbody>
</table>`
})
export class List { 

  const responseData={
   "message": " list received successfully",
   "success": "true",
   "data": {
   "_list": [
   {
    "id": "",
    "name": "",
    "image_url": null,
    "is_occupation": true
   },
   {
    "id": "",
    "name": "",
    "image_url": null,
    "is_occupation": true
   }],
   "responseCode":"",
  };

 }