WtFudgE
WtFudgE

Reputation: 5228

Angular bind table to generic object

I'm just starting to explore with Angular. Now what I'm trying to do is using an mvc handler that returns a jsonobject. However the returned jsonobject is generic, so it can be different types of object, and they all have a different amount of columns. I want to bind all these columns to a table, but that means i can't just create a fixed amount of columns and bind them like so:

<table class="table">
            <tr ng-repeat="r in items">
                <td>{{r.ID}}</td>
                <td>{{r.Name}}</td>
                <td>{{r.FirstName}}</td>
                <td>{{r.Telephone}}</td>
                <td>{{r.Email}}</td>
            </tr>
        </table>

this is NOT the way i want it, basically i want to have a table that binds to an object and that creates table columns for every property of the object.

thanks for any advice!

Upvotes: 2

Views: 781

Answers (1)

Rebornix
Rebornix

Reputation: 5270

You can iterate the properties of the value like

<tr ng-repeat="r in items">
  <td ng-repeat="(key, value) in r">
    {{ value }}
  </td>
</tr>

Upvotes: 1

Related Questions