0

Following is my json file. I want to iterate rewards array only. The following stuff iterate in *ngFor. I am iterating like this

<ul *ngFor="let rew of gdata?.rewards">
     <li> {{rew.rewardID}} </li>
</ul>

if anyone please help me I have searched lot.

gdata = [
 {
"id": 18,
"gname": "Learning Ramayanam",
"goalCategory": "Education",
"goalSubCategory": "Half-yearly",
"goalDesc": "good",
"rowStatusCode": "I",
"createID": "1",
"createTS": null,
"updateID": "Ram",
"updateTS": null,
"rewards": [
  {
    "rewardID": 25,
    "rewardName": "Amazon - pts",
    "rowStatusCode": "I",
    "createID": "1",
    "createTS": 1493785361000,
    "updateID": null,
    "updateTS": null
  },
  {
    "rewardID": 6,
    "rewardName": "Trends - 100000pts",
    "rowStatusCode": "U",
    "createID": "1",
    "createTS": 1493131878000,
    "updateID": null,
    "updateTS": null
  }
],
"initiatives": {
  "initID": 17,
  "initAction": "Stop",
  "startDate": "2017-04-27",
  "targetDate": "2017-04-30",
  "rowStatusCode": "U",
  "createID": "1",
  "createTS": 1493294143000,
  "updateID": null,
  "updateTS": null,
  "status": "red"
  }
 },

1 Answer 1

2

If you have only one item in gdata, you can do it with a single ngFor as below:

<ul>
    <li *ngFor="let rew of gdata[0]?.rewards">{{rew.rewardID}}</li>
</ul>

Else if you have multiple items in gdata, you may need nested ngFor to generate multiple lists.

<ul *ngFor="let data of gdata">
    <li *ngFor="let rew of data?.rewards">{{rew.rewardID}}</li>
</ul>

refer plunker.

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.