Matt Matt - 4 months ago 12
AngularJS Question

How can I bind a repeat to a table using an object literal?

I have this object called ct.items.columns ... and inside I have two strings , "id" and "name" .

And I want to bind in angular to build an dynamic table with two columns.. "id" and "name" from my literal.

I tried this:

<table border ="1">
<tr class="active">
<th ng-repeat = "a in ct.items.columns">

And I get nothing. My controller is set up properly.. I can make other bindings. In the object ct.items I have two properties.. columns and query... and in columns 0 - id and 1-name .

Answer Source

I'm not sure about your object but you can make dynamic table like this.

<div ng-controller="myCtrl">
            <th ng-repeat="(heading,val) in ct.items.columns">{{heading}}</th>

            <td ng-repeat="(heading,val) in ct.items.columns">{{val}}</td>

Working Demo

Hope this helps.