Search code examples
angularjsangularjs-ng-repeat

ng repeat in object with dynamic keys


I have a problem writing proper ng-repeat for this object. I would like to display all object properties. There is a main array of apps, each app can have a multiple versions and each version can have multiple users.

Here is object json.

"Awesome App 1": {
    "1.16": {
      "Steve": [
        "steve@example.com",
        null
      ],
      "Mike": [
        "mike@example.com",
        null
      ]
    }
  },
  "Awesome App 2": {
    "1.7.0": {
      "steve": [
        "steve@example.com",
        null
      ]
    }
  }, 

...

Problem is that keys are dynamic and I don`t know how to map it in ng-repeat. Thanks for a help.


Solution

  • You can try something like this:

    https://plnkr.co/edit/3wMdzrtkpShLgl8mu9sN

    $scope.data.json = {"Awesome App 1":
    ......
    };
    
        <ul>
           <li ng-repeat="(key, val) in data.json">
              App Name: {{key}} <br/>  
              <span ng-repeat="(key2, val2) in val">
                 Version: {{key2}} <br/>
                 <span ng-repeat="(key3, val3) in val2">
                   User: {{key3}} - {{val3[0]}} <br/>
                 </span>
              </span>
           </li>
       </ul>