最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed - Stack Overflow

programmeradmin5浏览0评论

I have a similar situation as described here but I use a $http call to get my data to build a infinite scrolling table, and get:

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: i in items, Duplicate key: string:b, Duplicate value: b

source code is here

this is the source code that i followed and it worked

i need help in this situation!

thanks

I have a similar situation as described here but I use a $http call to get my data to build a infinite scrolling table, and get:

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: i in items, Duplicate key: string:b, Duplicate value: b

source code is here

this is the source code that i followed and it worked

i need help in this situation!

thanks

Share Improve this question edited May 23, 2017 at 12:22 CommunityBot 11 silver badge asked Mar 18, 2015 at 7:46 aureliusaurelius 4,0769 gold badges42 silver badges78 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

You have a few issues in your jsFiddle. As noted above by @Manjesh V, you need to add track by $index, giving you:

<li ng-repeat="i in items track by $index">{{i.name}}</li>

Also, as mentioned by @sMr, you need to add $http module to the directive.

Finally, your jsFiddle links to a really old version of AngularJS, v1.0.0. You can add 1.2.1 and it will work.

Duplicate Items in the array, If you want to ignore use track by $index

<li ng-repeat="i in items track by $index">{{i.name}}</li>

it seems to be you have not passed the $http module to your main controller.

function Main($scope,$http) {
    $scope.items = [];

        $scope.loadMore = function() {
        $http.get('/echo/json').
                success(function(data, status, headers, config) {
                    // this callback will be called asynchronously
                    // when the response is available
                    $scope.items += data;
                }).
                error(function(data, status, headers, config) {
                    // called asynchronously if an error occurs
                    // or server returns response with an error status.
                    console.log("call failed");
                });
    };
    $scope.loadMore();
} 

working demo

发布评论

评论列表(0)

  1. 暂无评论