2

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!

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

4 Comments

Here is a fiddle that proves the answer: jsfiddle.net/consultwithmike/0rjq726g
@MichaelPerrenoud Thanks Michael, you rock!
@MichaelPerrenoud that's not correct, that only works for 1 object, not for an object list. But Rebornix' answer is correct! That worked fine, thanks so much :)
@WtFudgE, obviously. It's clearly not complex to extrapolate a loop right? The point was I had a working example for the object and it supports this answer.

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.