ng-repeat 不适用于表 <tr>但适用于列表 <li> [英] ng-repeat not working with table <tr> but works with list <li>

查看:36
本文介绍了ng-repeat 不适用于表 <tr>但适用于列表 <li>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:Plnkr 上的代码

我正在尝试在表中使用 ng-repeat.但这不起作用.而相同的代码适用于列表

  • I am trying to use ng-repeat within a table. But that doesnt work. Whereas the same code works for list <li>

    这里是相同的片段.

    <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>
    

    中使用 ng-repeat 是否不正确.我如何才能正确使用表.

    Is it incorrect to use ng-repeat within <tr>. How could i get the table usage right.

    推荐答案

    Per W3C HTML 表定义

    表格是用标签定义的.

    表格被分成带有标签的表格行.

    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>
    

    这篇关于ng-repeat 不适用于表 &lt;tr&gt;但适用于列表 &lt;li&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆