0

I am getting this error:

Duplicates in a repeater are not allowed. Repeater: session in privateKeyList key: string:I

This is my JavaScript code:

  success(function(data, status, headers, config) {
                      $scope.privateKeyList = data.privateKeyList;

                    $scope.totalPrivKey=data.totalPrivateKey;

This is my JSP code:

       <tbody  ng-repeat="session in privateKeyList">
          <tr>
                                <td>{{session.ptID}}</td>
                                <td>{{session.encID}}</td>
                                <td>{{session.doctorID}}</td>

         </tr>

This is the response in JSON string:

 {
  "privateKeyList":
     "[\"{key1:9315, key2:27108, key3:122 }\",
    \"{key1:9315, key2:27108, key3:122}\"]",

 "totalPrivateKey": 888  }
Parmar Kamlesh
  • 151
  • 1
  • 15

2 Answers2

1

By ref and by value

You are not creating a separate object for each item in your array. your array just holds a ref.

To get around this you can go to your repeat and add

ng-repeat="session in privateKeyList track by $index"

Objects

Should you need a new object for whatever reason you should just create it before you push to the array with Object.create

here is a link to a question that explains it.

Community
  • 1
  • 1
Joe Lloyd
  • 19,471
  • 7
  • 53
  • 81
1

Use the track by $index with ng-repeat and Use ng-repeat with <tr> tag.

<tbody>
          <tr ng-repeat="session in privateKeyList" track by $index>
                                <td>{{session.ptID}}</td>
                                <td>{{session.encID}}</td>
                                <td>{{session.doctorID}}</td>

         </tr>
</tbody>

Use the track by $index with ng-repeat Example

<div ng-repeat="obj in collection track by $id(obj)">
  {{obj.prop}}
</div>

<div ng-repeat="n in [42, 42, 43, 43] track by $index">
  {{n}}
</div>

for more know
https://docs.angularjs.org/api/ng/directive/ngRepeat

Vipin Jain
  • 3,686
  • 16
  • 35