0

I tried with few techniques but still I can't figure out it so what is the best way to show this data using angular *ngFor loop

  "data": {
    "live": [
      {
        "name": "First",
        "image": "XXXX",
        "description": "Blockchain Technology",
        "timezone": "UTC+0"
      },
      {
        "name": "First",
        "image": "XXXX",
        "description": "Blockchain Technology",
        "timezone": "UTC+0"
      }
    ]
  }
}
3

2 Answers 2

1

You actually do not need nested ngFor, you could just use it as follows,

<ul>
    <li *ngFor="let myObj of myData.data.live">
      {{ myObj.description }}
    </li>
</ul>

STACKBLITZ DEMO

Sign up to request clarification or add additional context in comments.

Comments

0

try with this Hope it will help you. In your component.ts file access the data from your JSON file like below.

yourdata: any = [];

this.httpService.get('./assets/yourjsonfile.json').subscribe(
       data => {
          this.yourdata = data as string [];
        },
        (err: HttpErrorResponse) => {
        console.log (err.message);
      }
    );

then in your component.html file try to access the content of the yourdata variable which we declared in the component.ts file as follows.

<div *ngFor="let Data of yourdata>
   {{ Data.data.live.name}}
   {{ Data.data.live.image}}
   {{ Data.data.live.description}}
   {{ Data.data.live.timezone}}
</div>

it will print your JSON data on your UI application.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.