-2

I have the following structure

[
  {
    "name": null
    "match": [{
                 "id": 0,
                 "location": ""

             "awayTeam": {
                     "id": 1568,
                     "teamName": "Manly United" },
                 "homeTeam": {
                     "id": 1523,
                     "teamName": "Sydney FC Youth" },
                     "matchDataProvider": [{
                            "id": 2953046,
                         "updatedDate": null }],
                 "matchPunditPrediction": [],
                 "matchResult": null,
                     "userMatchPrediction": []
               }]
   }
]

I need to iterate over the match element and retrieve properties

Fateh Mohamed
  • 20,445
  • 5
  • 43
  • 52
user1572257
  • 97
  • 11

2 Answers2

1

You can do by: arr = your full array.

arr.forEach(obj => {
  obj.match.forEach(m => {
    // This contains the match object.
    console.log(m);
    console.log(m.id);
  })
})

For html.

<div *ngFor="let item of myData">
  <div *ngFor="let match of item.match | json"> {{ match }} </div>
</div>
Muhammad Kamran
  • 978
  • 6
  • 10
1

I had the same array structure.In normal java logic we know that,we can element value by iterating two times for loop.So I tried to do same .I tried to write ngFor to iterate first array but I got the error as Found [object] instead of [Object object].Well this is surely not our fault but angulars ngFor loop only work with a proper array structure,it throws error when you iterate such kind of array structure.

After So many research I found one hack,

In your component file just write below code.

hack(val) {
    return Array.from(val);
  }

This will make array upon array. Magic is ,Angular finds this as proper array structure and it will not give error after.

Now when you write ngFor in html ,just write like this.

*ngFor="let variablename of hack(arrayObjectname)"

after this, if you need to write ngFor again for inside array,you still can write now :).This hack might show error in your code platform but it will run fine in browser.

I hope this will help you to solve your issue :)

Arjun
  • 1,294
  • 13
  • 24