angularjs ng-repeat重复项目

时间:2014-12-28 13:11:14

标签: javascript angularjs

我正在使用带有角度js ng-repeat的http请求来重新填充列表。

它是这样的:

<div class="item" ng-repeat="item in itemlist">
    content goes here...
</div>

,在控制器中,我调用一个带间隔的函数,将item变量设置为新列表:

$ app.communicate是一个向服务器发出http请求的函数

    initializeItemList = function() {
        $app.communicate('item','loadItemList',{user_id : localStorage.userId},function(data, status, headers, config) {
            $scope.recent_item = data.recent_item;
            $scope.itemlist= data.itemlist;
            }
        },function() {});       
    };

    initializeItemList();

    $interval(initializeItemList, 4000);

实际上,每个间隔运行都会重复项目列表。

我尝试添加过滤器唯一,但它无济于事..

1 个答案:

答案 0 :(得分:4)

使用追踪

<div class="item" ng-repeat="item in itemlist track by $index">
    content goes here...
</div>