Search code examples
angularjsangularjs-ng-repeat

Array index into column in AngularJS using ng-repeat


I need help in getting JSON array index into table columns using AngularJS ng-repeat. Below is the JSON and I want to convert it to a HTML table:

{
  "Employee": [
    {
      "Name": "`Rocky`",
      "Location": "Office"
    },
    {
      "Name": "John",
      "Location": "Home"
    }
  ]
}
<table>
    <tbody>
        <tr>
            <td>Rocky</td>
            <td>John</td>
        </tr>
        <tr>
            <td>Office</td>
            <td>Home</td>
        </tr>
    </tbody>
</table>

Solution

  • You can do it this way:

    <table>
      <tbody>
          <tr ng-repeat="list in object.Employee">
              <td>{{list.Name}}</td>
              <td>{{list.Location}}</td>
          </tr>
      </tbody>
    </table>
    

    http://jsfiddle.net/Lvc0u55v/8699/