Angular JS Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed

I am facing an issue of [ngRepeat:dupes].

systemService.getAllSystemSettings().then(
  function (obj) {
    $scope.project.meta.franchise = obj.find(item => item.keyword === "Program");
    console.log($scope.project.meta.franchise);
    $scope.project.meta.franchise = $scope.project.meta.franchise['keywordValue'].split(';');
    console.log($scope.project.meta.franchise);
    return $scope.project.meta.franchise);
  });

in my HTML page :

<select class="form-control" ng-model="project.meta.franchise" ng-disabled="readOnlyUser">
  <option ng-repeat="option in project.meta.franchise" value="{{option}}">{{option}}</option>
</select>

Output in console :

{ keyword: "Program", keywordValue: "test_abc;abc_&xyz;efg_&_hij"
}
[
  "test_abc",
  "abc_&xyz",
  "efg_&_hij"
]

error in console:

enter image description here

Please help me out in solving I tried putting track by $ index but no solution with that too. By using $track by it does not show the list in options. ThankYou in advance.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Try changing the value of the ng-model to project.franchise in your HTML code. Below is the code I applied and it worked for me:-

<select class="form-control" ng-model="project.franchise" ng-disabled="readOnlyUser">
  <option ng-repeat="option in project.meta.franchise)" value="{{option}}">{{option}}</option>
</select>

Solution 2

try to make a custom unique index like this

<select class="form-control" ng-model="project.meta.franchise)" ng-disabled="readOnlyUser">
   <option ng-repeat="option in project.meta.franchise track by ($index + ':' + option)" value="{{option}}">{{option}}</option>
 </select>

Solution 3

Try giving multiple = ‘true’ in your HTML select statement. Please refer to Davis Ford’s post in GitHub regarding the same.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply