Angular ng-repeat Error “Duplicates in a repeater are not allowed.”

后端 未结 10 2350
青春惊慌失措
青春惊慌失措 2020-11-22 06:11

I am defining a custom filter like so:

相关标签:
10条回答
  • 2020-11-22 06:26

    Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: sdetail in mydt, Duplicate key: string: , Duplicate value:

    I faced this error because i had written wrong database name in my php api part......

    So this error may also occurs when you are fetching the data from database base, whose name is written incorrect by you.

    0 讨论(0)
  • 2020-11-22 06:27

    If you call a ng-repeat within a < ul> tag, you may be able to allow duplicates. See this link for reference. See Todo2.html

    0 讨论(0)
  • 2020-11-22 06:30

    My JSON response was like this:

    {"items": 
      &nbsp;[
        &nbsp;&nbsp;{
          "index": 1,
          "name": "Samantha",
          "rarity": "Scarborough",
          "email": "maureen@sykes.mk"
        },
        &nbsp;&nbsp;{
          "index": 2,
          "name": "Amanda",
          "rarity": "Vick",
          "email": "jessica@livingston.mv"
        }]
    }
    

    So, I used ng-repeat = "item in variables.items" to display it.

    0 讨论(0)
  • 2020-11-22 06:37

    I was having an issue in my project where I was using ng-repeat track by $index but the products were not getting reflecting when data comes from database. My code is as below:

    <div ng-repeat="product in productList.productList track by $index">
      <product info="product"></product>
     </div>
    

    In the above code, product is a separate directive to display the product.But i came to know that $index causes issue when we pass data out from the scope. So the data losses and DOM can not be updated.

    I found the solution by using product.id as a key in ng-repeat like below:

    <div ng-repeat="product in productList.productList track by product.id">
      <product info="product"></product>
     </div>
    

    But the above code again fails and throws the below error when more than one product comes with same id:

    angular.js:11706 Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater

    So finally i solved the problem by making dynamic unique key of ng-repeat like below:

    <div ng-repeat="product in productList.productList track by (product.id + $index)">
      <product info="product"></product>
     </div>
    

    This solved my problem and hope this will help you in future.

    0 讨论(0)
  • 2020-11-22 06:37

    Just in case this happens to someone else, I'm documenting this here, I was getting this error because I mistakenly set the ng-model the same as the ng-repeat array:

     <select ng-model="list_views">
         <option ng-selected="{{view == config.list_view}}"
             ng-repeat="view in list_views"
             value="{{view}}">
             {{view}}
         </option>
     </select>
    

    Instead of:

    <select ng-model="config.list_view">
         <option ng-selected="{{view == config.list_view}}"
             ng-repeat="view in list_views"
             value="{{view}}">
             {{view}}
         </option>
     </select>
    

    I checked the array and didn't have any duplicates, just double check your variables.

    0 讨论(0)
  • 2020-11-22 06:41

    If by chance this error happens when working with SharePoint 2010: Rename your .json file extensions and be sure to update your restService path. No additional "track by $index" was required.

    Luckily I was forwarded this link to this rationale:

    .json becomes an important file type in SP2010. SP2010 includes certains webservice endpoints. The location of these files is 14hive\isapi folder. The extension of these files are .json. That is the reason it gives such a error.

    "cares only that the contents of a json file is json - not its file extension"

    Once the file extensions are changed, should be all set.

    0 讨论(0)
提交回复
热议问题