Estoy tratando de insertar datos de un modelo en una plantilla, pero quiero agregar una nueva fila de tabla después de cada 7 repeticiones. Con plantillas basadas en strings, podría hacerlo bastante fácilmente usando el índice de iteración y el módulo, pero no puedo entender cómo hacerlo usando las plantillas DOM de angular.Usando ng-repeat con filas de tabla
Aquí está el código HTML:
<div ng-controller="MyCtrl">
<table cellspacing="0" cellpadding="0">
<colgroup span="7"></colgroup>
<tbody>
<tr class="days">
<th scope="col" title="Monday">Mon</th>
<th scope="col" title="Tuesday">Tue</th>
<th scope="col" title="Wednesday">Wed</th>
<th scope="col" title="Thursday">Thu</th>
<th scope="col" title="Friday">Fri</th>
<th scope="col" title="Saturday">Sat</th>
<th scope="col" title="Sunday">Sun</th>
</tr>
<tr>
<td ng-repeat="date in dates">
{{ date }}
<!-- After seven iterations a new `<tr>` should be aded -->
</td>
</tr>
</tbody>
</table>
</div>
Y el javascript, algo así como:
myApp = this.angular.module('myApp', []);
var monthDays = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1516, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
myApp.controller('MyCtrl', function($scope) {
return $scope.dates = monthDays;
});
Usted puede ver el código en un jsFiddle aquí: http://jsfiddle.net/3zhbB/2/
Gracias, esperaba que podría ser una manera de hazlo dentro de la plantilla sin alterar la matriz en el controlador. Sin embargo, no parece que esto sea posible en este momento. – DaveJ
Creé un filtro que se puede reutilizar basado en esta respuesta: http://jsfiddle.net/interlock/qhewP/2/ – jsapara