简体   繁体   中英

How to print all data in angular html page usigng ngFor

I have a data collection as below and I need to print these information on a HTML page using the ngFor loop.

[
  {_id: "5ed387946094abebeaa6e75a", name: "Andaman and Nicobar Islands", active: 0, cured: 33, death: 0},
  {_id: "5ed387946094abebeaa6e75b", name: "Andhra Pradesh", active: 1654, cured: 2576, death: 73},
  {_id: "5ed387956094abebeaa6e75c", name: "Arunachal Pradesh", active: 44, cured: 1, death: 0},
  {_id: "5ed387966094abebeaa6e75d", name: "Assam", active: 1651, cured: 498, death: 4},
  {_id: "5ed387966094abebeaa6e75e", name: "Bihar", active: 2342, cured: 2225, death: 29},
  {_id: "5ed387966094abebeaa6e75f", name: "Chandigarh", active: 77, cured: 222, death: 5},
  {_id: "5ed387976094abebeaa6e760", name: "Chhattisgarh", active: 633, cured: 244, death: 2}
]

Option 1: json pipe

<ng-container *ngFor="let item of state">
  {{ item | json }}
</ng-container>

Option 2: keyvalue pipe

<ng-container *ngFor="let item of state">
  <ng-container *ngFor="let property of item | keyvalue">
    {{ property.key }}: {{ property.value }}
  </ng-container>
</ng-container>

Option 3: Access properties directly

<ng-container *ngFor="let item of state">
  {{ item?.name }}
  {{ item?.active }}
  {{ item?.cured }}
  {{ item?.death }}
  ...
</ng-container>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM