Reputation: 59
I have list that I need to traverse in using angular js. I want to create row dynamically with two column and each column should show different element(record) info from list.
Upvotes: 0
Views: 359
Reputation: 7156
It's quite simple...
I created an example.
Plunker link: Click here
Note: I created a dummy example for you. You have to maintain some code according to your array.
Upvotes: 0
Reputation: 101
Instead of using ng-repeat in tr element , you should use it in td element if you want column based dynamics
Upvotes: 0
Reputation: 1354
in controller have your list-array
vm.myList = [{key:'value', key2: 'value2'}, {key:'value', key2: 'value2'}];
in html use the directive ng-repeat
to iterate over the array
<table>
<tbody>
<th>Key</th>
<th>Key2</th>
</tbdoy>
<tr ng-repeat="item in vm.myList">
<td>{{item.key}}</td>
<td>{{item.key2}}</td>
</tr>
</table>
if wann to add more rows in controller push it to the array
vm.myList.push({key:'newValue', key2:'otherValue'});
Upvotes: 0
Reputation: 17299
You can use ng-repeat
directive to traverse list
item. Which means whenever you want to push element in DOM, do push it inside collection listItems
, ng-repeat
will take care of rest.
<table>
<tr ng-repeat="item in listItems">
<td>{{item.property1}}</td>
<td>{{item.property2}}</td>
</tr>
</table>
Upvotes: 1