× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How to use values in nested ng-repeat

Ryan McDevitt
Aug 19, 2014
<p>During a recent Codementor session, a user asked about how to use&nbsp;nested ng-repeats to build a HTML table using both dynamic tables and rows. &nbsp;</p><p>I clarified the syntax of aliasing inside of the angulars directives.&nbsp;</p><p><br><strong>Quick Tip:&nbsp;</strong></p><pre><code class="language-javascript">//contoller $scope.headers = ['header1','header2', 'header3']; $scope.data = [ { 'header1': 'data1-1', 'header2': 'data1-2', 'header3': 'data1-3' }, { 'header1': 'data2-1', 'header2': 'data2-2', 'header3': 'data2-3' } //... ] </code></pre><pre><code class="language-html">&lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th ng-repeat="field in headers"&gt;{{header}}&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr ng-repeat="row in data"&gt; &lt;td ng-repeat="field in headers"&gt;{{ row[field] }}&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;</code></pre><p>&nbsp;</p><p>&nbsp;</p>