加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 角度ng重复错误“不允许重复器中的重复”

发布时间:2020-12-17 09:26:22 所属栏目:安全 来源:网络整理
导读:我定义一个自定义过滤器,如: 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-re
我定义一个自定义过滤器,如:
<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;
    };
});

我越来越:

Error: Duplicates in a repeater are not allowed. Repeater: comment in item.comments | range:1:2 ngRepeatAction@07000

解决方案实际上描述如下: http://www.anujgakhar.com/2013/06/15/duplicates-in-a-repeater-are-not-allowed-in-angularjs/

AngularJS不允许在ng-repeat指令中重复。这意味着如果你试图做以下,你会得到一个错误。

// 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]">

然而,稍微改变上述代码以定义索引以确定如下的唯一性将使其再次工作。

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读