微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我定义一个自定义过滤器,如:
<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

原文地址:https://www.jb51.cc/angularjs/147673.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐