1

I have a JSON structure where I want to loop through the data within an array, but I can't seem to get it working with ng-repeat in AngularJS.

This is the JSON structure

{
    "header": ["header1", "header2"],
    "content": {
        "Data1": ["data1", "data2"],
        "Data2": ["data1", "data2"]
    }
}

In my html I do this:

<div ng-repeat="item in header">
  <li>{{item}}</li>
  <div ng-repeat="(key, value) in content">
    <li>{{key}}</li>
    <li>{{value}}</li>
  </div>
</div>

The header data is retrieved fine but I can't loop through the arrays in the Data1 and Data2 objects

1
  • can you create a reproducible demo of the issue using stack snippets.. And do you get any errors? Commented Oct 10, 2019 at 6:48

1 Answer 1

1

Try this

<div ng-repeat="item in header track by $index">
  <li>{{item}}</li>
  <div ng-repeat="(key, value) in content track by $index">
    <li>{{key}}</li>
    <li ng-repeat="val in value track by $index">{{val}}</li>
  </div>
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

Not working unfortunately. Getting error: Error: "[ngRepeat:dupes]"

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.