角NG重复错误"重复在一个中继器不允许&QUOT。 [英] Angular ng-repeat Error "Duplicates in a repeater are not allowed."

查看:90
本文介绍了角NG重复错误"重复在一个中继器不允许&QUOT。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义自定义过滤器,像这样:

 < D​​IV CLASS =想法项目NG重复=项中的项目isoatom>
    < D​​IV CLASS =部分评论clearfixNG重复=在item.comments评论|范围:1:2>
        ....
    < / DIV>
< / DIV>

正如你所看到的NG-重复,其中正在使用的过滤器嵌套在另一个NG重复内

该过滤器是这样定义的:

  myapp.filter('范围',函数(){
    返回功能(输入,最小,最大){
        分= parseInt函数(分钟); //使字符串输入INT
        最大= parseInt函数(最大值);
        对于(VAR I =分钟; I<最大;我++)
            input.push(ⅰ);
        返回输入;
    };
});

我收到:


  

错误:在一个中继器不允许重复。中继器:在item.comments评论|范围:1:2 ngRepeatAction @ <一个href=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/an\">https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/an



解决方案

该解决方案实际上是描述如下:<一href=\"http://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/\">http://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/

AngularJS不允许在一个纳克重复指令的重复。这意味着如果你正在尝试做以下,你会得到一个错误。

  //下面将抛出一个中继器的错误不允许重复。中继器:行[1,1,1]键:数字:1
&LT; D​​IV NG重复=行[1,1,1]&GT;

然而,改变上述$ C $小幅C中定义的索引来确定唯一性,下面将得到它的工作了。

  //这将工作
&LT; D​​IV NG重复=行[1,1,1]轨道由$指数&GT;

官方文档是在这里:<一href=\"https://docs.angularjs.org/error/ngRepeat/dupes\">https://docs.angularjs.org/error/ngRepeat/dupes

I am defining a custom filter like so:

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

As you can see the ng-repeat where the filter is being used is nested within another ng-repeat

The filter is defined like this:

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;
    };
});

I'm getting:

Error: Duplicates in a repeater are not allowed. Repeater: comment in item.comments | range:1:2 ngRepeatAction@https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/an

解决方案

The solution is actually described here: http://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/

AngularJS does not allow duplicates in a ng-repeat directive. This means if you are trying to do the following, you will get an error.

// the below will throw 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]">

However, changing the above code slightly to define an index to determine uniqueness as below will get it working again.

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

Official docs are here: https://docs.angularjs.org/error/ngRepeat/dupes

这篇关于角NG重复错误&QUOT;重复在一个中继器不允许&QUOT。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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