1

here actually the full error: Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: orang in orangs, Duplicate key: string:", Duplicate value: "

here is my html code:

<ion-view view-title="Daftar Orang">
  <ion-content>
    <ion-list>
      <ion-item ng-repeat="orang in orangs">
        {{orang.nama}}
      </ion-item>
    </ion-list>
  </ion-content>
</ion-view>

here is my angular controller:

.controller('OrangCtrl', function($scope, $http, $ionicLoading, $ionicHistory) {

  $ionicHistory.nextViewOptions({
    disableBack: true
  });

  //loading
  $scope.show = function() {
    $ionicLoading.show({
      template: '<ion-spinner icon="android"></ion-spinner><br>Harap Tunggu'
    }).then(function(){
       console.log("The loading indicator is now displayed");
    });
  };
  $scope.hide = function(){
    $ionicLoading.hide().then(function(){
       console.log("The loading indicator is now hidden");
    });
  };  
    $scope.show();
    $http({
        url: "http://localhost/android_server/orang/read?key=vr46",
        method: "GET",
        data: {}
    })
    .then(function(response) {
        $scope.myData = response.data;
        $scope.hide();
          $scope.orangs = angular.toJson($scope.myData.data);
          console.log('Response Data', $scope.orangs);

    });   

})

and here is my codeigniter rest_server controller:

    <?php

require(APPPATH.'libraries/REST_Controller.php');

class Orang extends REST_Controller {

    public function __construct(){
        parent::__construct();
            date_default_timezone_set("Asia/Jakarta");

        if (isset($_SERVER['HTTP_ORIGIN'])) {
            header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
            header('Access-Control-Allow-Credentials: true');
            header('Access-Control-Max-Age: 86400');    // cache for 1 day
        }

        // Access-Control headers are received during OPTIONS requests
        if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

            if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
                header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

            if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
                header("Access-Control-Allow-Headers:        
                {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

            exit(0);
        }           


    }

    function read_get()
    {
        $data = $this->db->order_by('id', 'DESC')->get('orang')->result();
        if($data){
            $response['data'] = $data;
            $response['status'] = 1;
        }else{
            $response['status'] = 0;
            $response['message'] = 'Data tidak ada';
        }   
        $this->response($response);
    }
}

i used codeigniter rest server to get the data.

Dimas Adi Andrea
  • 443
  • 3
  • 11
  • 25
  • Possible duplicate of [Angular ng-repeat Error "Duplicates in a repeater are not allowed."](http://stackoverflow.com/questions/16296670/angular-ng-repeat-error-duplicates-in-a-repeater-are-not-allowed) – Hassaan Aug 01 '16 at 05:17

1 Answers1

3

Add 'track by $index' to your ng-repeat.

<ion-item ng-repeat="orang in orangs track by $index">
  {{orang.nama}}
</ion-item>

Angular doesn't like duplicate keys in it's repeaters. This will track them by their index instead. See a more detailed explanation here.

jjwilly16
  • 410
  • 2
  • 8
  • 15