Refresher shows doubles


#1

Hi, I used the ionic refresher to update a json file.
Everything works fine, but the first second or so, all objects are appearing 2 times.
After a second or so, it just shows the array fine.

Here’s my code:

app.controller('tableController', function ($scope, $http) {

    $scope.getData = function (jsonstring) {
        $http.get(jsonstring).then(function (res) {
            $scope.data = res.data;
            $scope.$broadcast('scroll.refreshComplete');
        });
    };
            
    $scope.getData('*somejson*');       

    $scope.refreshData = function () {
        $scope.getData(*someotherjson*);
    };
});

And my view:

<ion-view title="My app'" left-buttons="leftButtons">
    <ion-content has-header="true" padding="true" on-refresh="refreshData()">
        <ion-refresher></ion-refresher>
        <div class="list">
            <ion-item ng-repeat="user in data" item="item">
                <div class="row">
                    <div class="col">{{user.id}}</div>                        
                </div>
            </ion-item>
        </div>
    </ion-content>
</ion-view>

Any help ? Thanks in advance.


#2

Add a track by expression to your ng-repeat.

<ion-item ng-repeat="user in data track by user.id" item="item">

#3

Thanks a lot, that fixed it.


#4

did not work for me. been having this issue for months. i was already use track by before it started happening