Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing ng-repeat with table rows
    primarykey
    data
    text
    <p>I'm trying to insert data from a model into a template but I want to add a new table row after every 7 repetitions. With strign-based templates I could do it quite easily using the iteration index and modulo but I can't quite figure out how to do this using angular's DOM templates.</p> <p>Here's the HTML:</p> <pre><code>&lt;div ng-controller="MyCtrl"&gt; &lt;table cellspacing="0" cellpadding="0"&gt; &lt;colgroup span="7"&gt;&lt;/colgroup&gt; &lt;tbody&gt; &lt;tr class="days"&gt; &lt;th scope="col" title="Monday"&gt;Mon&lt;/th&gt; &lt;th scope="col" title="Tuesday"&gt;Tue&lt;/th&gt; &lt;th scope="col" title="Wednesday"&gt;Wed&lt;/th&gt; &lt;th scope="col" title="Thursday"&gt;Thu&lt;/th&gt; &lt;th scope="col" title="Friday"&gt;Fri&lt;/th&gt; &lt;th scope="col" title="Saturday"&gt;Sat&lt;/th&gt; &lt;th scope="col" title="Sunday"&gt;Sun&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td ng-repeat="date in dates"&gt; {{ date }} &lt;!-- After seven iterations a new `&lt;tr&gt;` should be aded --&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>And the javascript it something like:</p> <pre><code>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; });​ </code></pre> <p>You can view the code in a JSFiddle here: <a href="http://jsfiddle.net/3zhbB/2/" rel="noreferrer">http://jsfiddle.net/3zhbB/2/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload