角度ng重复,元素之外的内容

时间:2016-09-19 01:20:30

标签: javascript html angularjs

在我的源代码中,我有以下HTML块:

<h3> Players </h3>
    <table class="popup-winloss-table">
        <tbody >
            <tr ng-repeat="player in focusedTeamMembers">
                sample text
                {{player}}
            </tr>
        </tbody>
    </table>

目前,focusedTeamMembers有3个元素。

然而,在使用角度后,我的浏览器会显示以下代码:

<h3> Players </h3>
sample text
<table class="popup-winloss-table">
   <tbody>
      <!-- ngRepeat: player in focusedTeamMembers -->
      <tr ng-repeat="player in focusedTeamMembers" class="ng-scope"></tr>
      <!-- end ngRepeat: player in focusedTeamMembers -->
      <tr ng-repeat="player in focusedTeamMembers" class="ng-scope"></tr>
      <!-- end ngRepeat: player in focusedTeamMembers -->
      <tr ng-repeat="player in focusedTeamMembers" class="ng-scope"></tr>
      <!-- end ngRepeat: player in focusedTeamMembers -->
   </tbody>
</table>

有人可以解释为什么&#34;示例文本&#34;正在显示标有&#34; ng-repeat&#34;的元素之外,以及如何在<tr>元素中显示它?

附加信息:如果在&#34; ng-repeat&#34;我放入{{this.focusedTeamMembers}}的元素,显示对象的JSON,所以我很确定问题不在于变量不存在或未定义。

1 个答案:

答案 0 :(得分:0)

这可能是浏览器的错,而不是Angular的错。您提供了无效标记,因为<tr>内唯一有效的元素是<td><th>。其他任何内容(如示例文本)都会被浏览器移到桌面外,试图提供帮助并更正无效标记。

如果你现在只添加一个<td>,这应该足以开始了:

<h3> Players </h3>
<table class="popup-winloss-table">
    <tbody >
        <tr ng-repeat="player in focusedTeamMembers">
            <td>
                sample text
                {{player}}
            </td>
        </tr>
    </tbody>
</table>