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  }

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.