不确定为什么ng-repeat-start和ng-repeat-end抛出异常

时间:2016-12-06 14:37:06

标签: javascript angularjs angularjs-ng-repeat

首先是我想要实现的背景,

<tr  ng-repeat-start="eachParam in myArray">
    <td rowspan=2>On site</td>
    <td rowspan="2" class = "success">{{eachParam.support}}</td>
    <td class = "warning">FE</td>
</tr>
<tr>
    <td class = "warning">BE</td>
</tr ng-repeat-end>

我希望它能够创建如下的结构:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


<table class = "table table-bordered">
  <tbody>
    <!-- Repeat 1-->
    <tr>
      <td rowspan = 2>super parent1</td>
      <td rowspan = 2>parent1.1</td>
      <td>child 1.1.1</td>
    </tr>
    
    <tr>
      <td>child 1.1.2</td>
    </tr>
    <!-- Repeat 2-->
    <tr>
      <td rowspan = 2>super parent2</td>
      <td rowspan = 2>parent2.1</td>
      <td>child 2.1.1</td>
    </tr>
    
    <tr>
      <td>child 2.1.2</td>
    </tr>
  </tbody>
</table>

您可以在代码段中看到,我想使用ng-repeat-startng-repeat-end重复这两位超级父母,以便在我外出时不会遗漏中级<tr>重复超级父母或父母。

请注意childs是静态元素。

现在我得到的例外是:

  

未终止属性,找到'ng-repeat-start'但没有匹配   发现'ng-repeat-end'

1 个答案:

答案 0 :(得分:2)

您应该将ng-repeat-end添加到tr标记的开头,而不是结束标记。像这样:

<tr ng-repeat-start="eachParam in myArray">
    <td rowspan=2>On site</td>
    <td rowspan="2" class = "success">{{eachParam.support}}</td>
    <td class = "warning">FE</td>
</tr>
<tr ng-repeat-end>
    <td class = "warning">BE</td>
</tr>