admin管理员组文章数量:1279016
I have the following code: Code on Plnkr
I am trying to use ng-repeat
within a table. But that doesnt work. Whereas the same code works for list <li>
Here is a snippet of the same.
<h1>Using list</h1>
<ul>
<li ng-repeat="item in sampleArray">{{item}}</li>
</ul>
<h1>Using Table</h1>
<table>
<tr ng-repeat="item in sampleArray">{{item}}</tr>
</table>
Is it incorrect to use ng-repeat within <tr>
. How could i get the table usage right.
I have the following code: Code on Plnkr
I am trying to use ng-repeat
within a table. But that doesnt work. Whereas the same code works for list <li>
Here is a snippet of the same.
<h1>Using list</h1>
<ul>
<li ng-repeat="item in sampleArray">{{item}}</li>
</ul>
<h1>Using Table</h1>
<table>
<tr ng-repeat="item in sampleArray">{{item}}</tr>
</table>
Is it incorrect to use ng-repeat within <tr>
. How could i get the table usage right.
-
You might want to put in some
<td>
in the<tr>
:<tr ng-repeat=""><td>{{item}}</td></tr>
– Callum Linington Commented Feb 15, 2015 at 12:24
3 Answers
Reset to default 6Per W3C HTML Table definition
Tables are defined with the tag.
Tables are divided into table rows with the tag.
Table rows are divided into table data with the tag.
A table row can also be divided into table headings with the tag.
So the root cause is that you miss a <td>
or <th>
element inside your <tr>
element
<tr ng-repeat="item in sampleArray"><td>{{item}}</td></tr>
As you building a table with the ng-repeat
, you should specify the content of each row cells, with the td
tag like this:
<table>
<tr ng-repeat="item in sampleArray">
<td>{{$index}}</td>
<td>{{item}}</td>
</tr>
</table>
Yeah, checked on the plunker,
You need to remember to put in the <td>
into the <tr>
. <td>
is display element and <tr>
is structural.
<tr ng-repeat="item in sampleArray"><td>{{item}}</td></tr>
本文标签: javascriptngrepeat not working with table lttrgt but works with list ltligtStack Overflow
版权声明:本文标题:javascript - ng-repeat not working with table <tr> but works with list <li> - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741209806a2358885.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论