错误:[ngRepeat:dupes]不允许在转发器中重复

时间:2015-03-18 07:46:48

标签: javascript angularjs

我有类似here描述的情况,但我使用$ http调用来获取我的数据来构建无限滚动表, 得到:

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

源代码为here

this是我遵循的源代码,它起作用

在这种情况下我需要帮助!

感谢

3 个答案:

答案 0 :(得分:4)

你的jsFiddle中有一些问题。如上所述@Manjesh V,您需要添加track by $index,为您提供:

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

另外,如@sMr所述,您需要将$http模块添加到指令中。

最后,你的jsFiddle链接到一个非常旧版本的AngularJS,v1.0.0。您可以添加1.2.1,它将起作用。

答案 1 :(得分:3)

数组中的重复项目,如果您要忽略使用 track by $index

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

答案 2 :(得分:1)

似乎您没有将$http模块传递给主控制器。

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

工作demo

相关问题