Reputation: 19
How can I fill in the following table html structure with json data in a dynamic way? (with AngularJS).
Here is the basic HTML structure:
<table class="some styling">
<tbody>
<tr>
<td><a title="test" href="#"><span>Just some tests</span></a></td>
<td><a title="test" href="#"><span>Just some tests</span></a></td>
<td><a title="test" href="#"><span>Just some tests</span></a></td>
</tr>
<tr>
<td><a title="test" href="#"><span>Just some tests</span></a></td>
<td><a title="test" href="#"><span>Just some tests</span></a></td>
<td><a title="test" href="#"><span>Just some tests</span></a></td>
</tr>
</tbody>
</table>
The difficult part is how to determine the "tr" elements. There are always 3 td elements in 1 tr element. Only the amount of TD elements may vary.
Thanks in advance
Upvotes: 2
Views: 140
Reputation: 407
Html:
<table border="1" style="border-collapse: collapse">
<tr>
<th>id</th>
<th>firstname</th>
<th>lastname</th>
</tr>
<tr ng-repeat="user in users">
<td>{{user.id}}</td>
<td>{{user.firstname}}</td>
<td>{{user.lastname}}</td>
</tr>
</table>
Json:
$scope.users=[
{id:1,firstname:"naresh",lastname:"kumar"},
{id:2,firstname:"suresh",lastname:"kumar"},
{id:3,firstname:"harish",lastname:"kumar"},
]
this is the example am posting you can manipulate it. you can a have look here https://plnkr.co/edit/umC2hwECePaAqZ0huYoK?p=preview
Upvotes: 1