16

嗨,我有一个用于 ng-repeat-start 和 end 的简单用例,并且工作正常,当我想添加内部 ng-repeat 时出现问题。这是我的代码

<tr ng-repeat-start="obj in rows" >
  <td ng-repeat="e in obj.row">{{e}}</td>
</tr>
<tr ng-repeat-end>
  <td colspan="4">{{obj.description}}</td>
<tr>

td 元素的内部 ng-repeat 不起作用,我在检查 html 源代码时看到了 ngRepeat 注释,但没有创建 td 元素。

<!-- ngRepeat: e in obj.row -->

我丑陋的解决方法(鉴于我知道该向量的大小)是:

<tr ng-repeat-start="obj in rows" >
  <td>{{obj.row[0]}}</td>
  <td>{{obj.row[1]}}</td>
  <td>{{obj.row[2]}}</td>
  <td>{{obj.row[3]}}</td>
</tr>
<tr ng-repeat-end>
  <td colspan="4">{{obj.description}}</td>
<tr>
4

3 回答 3

19

I am not sure whether you are using angular 1.1.6 or not since ng-repeat-start and ng-repeat-end are not available in 1.1.5 or 1.0.7 yet.

However, you don't actually have to use the new directives to achieve that. You can simply implement it like this for right now:

<table>
    <tbody ng-repeat="obj in rows">
        <tr ng-repeat="e in obj.row">
            <td>{{e}}</td>
        </tr>
        <tr>
            <td colspan="4">{{obj.description}}</td>
        <tr>
    </tbody>
</table>

You may use ng-repeat-start and ng-repeat-end to reimplement it when AngularJS 1.1.6 version is officially released.

Demo

于 2013-08-09T23:00:58.817 回答
2

我认为您的数据结构可能有问题。使用 Angular 1.2.1这对我有用

<div ng-app="myApp" ng-controller="myCtrl">
    <div class="h" ng-repeat-start="val in data">{{val.title}}</div>
    <div ng-repeat="con in val.content">
        {{con}}
    </div>
    <div class="b" ng-repeat-end>footer</div>
</div>

jsFiddle

于 2014-02-26T03:18:24.083 回答
1

您应该能够使用基于索引的迭代来绕过它:

<tr ng-repeat-start="obj in rows" >
  <td ng-repeat="e in obj.row">{{obj.row[$index]}}</td>
</tr>
<tr ng-repeat-end>
<!-- ... -->
于 2013-08-09T22:00:37.973 回答