Reputation: 2573
How can i insert some custom rows after Nth row is created in angular js. For example in checklist items there are 10 objects and i have to put two extra rows after sixth row.
<html>
<table>
<thead>
<tr>
<th>Task</th>
<th>N/A</th>
<th>Date Completed</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in checklist">
<td>{{item.taskName}}</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="text">
</td>
</tr>
</tbody>
</table>
</html>
Upvotes: 2
Views: 1388
Reputation: 1479
Use $index variable of ng-repeat directive. like : ->
<html>
<body>
<table>
<thead>
<tr>
<th>Task</th>
<th>N/A</th>
<th>Date Completed</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in checklist" ng-if="$index<=6">
<td>{{item.taskName}}</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="text">
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr ng-repeat="item in checklist" ng-if="$index>6">
<td>{{item.taskName}}</td>
<td>
<input type="checkbox">
</td>
<td>
<input type="text">
</td>
</tr>
</tbody>
</table>
</body>
</html>
Upvotes: 3
Reputation: 451
See the documentation for splice()
. It can either add or remove items from an array at any given index. You'll want something along the lines of arrayOfItems.splice(5, 0, addAfter6thItem)
Upvotes: 0