Angular ng-repeat错误“不允许在转发器中重复”

问题描述

该解决方案实际上在这里进行了描述:http ://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in- angularjs/

AngularJS不允许在ng-repeat指令中重复。这意味着,如果您尝试执行以下操作,将会收到错误消息。

// This code throws the error "Duplicates in a repeater are not allowed.
// Repeater: row in [1,1,1] key: number:1"
<div ng-repeat="row in [1,1,1]">

但是,稍微更改上面的代码以定义一个索引来确定唯一性,如下所示,它将使它再次工作。

// This will work
<div ng-repeat="row in [1,1,1] track by $index">

官方文档在这里:https ://docs.angularjs.org/error/ngRepeat/dupes

解决方法

我正在定义一个自定义过滤器,如下所示:

<div class="idea item" ng-repeat="item in items" isoatom>    
    <div class="section comment clearfix" ng-repeat="comment in item.comments | range:1:2">
        ....
    </div>
</div>

如您所见,使用过滤器的ng-repeat嵌套在另一个ng-repeat中

过滤器的定义如下:

myapp.filter('range',function() {
    return function(input,min,max) {
        min = parseInt(min); //Make string input int
        max = parseInt(max);
        for (var i=min; i<max; i++)
            input.push(i);
        return input;
    };
});

我越来越:

错误:不允许在转发器中重复。中继器:在item.comments中发表评论| 范围:1:2 ngRepeatAction @
https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/an

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...