0

I am stuck at this issue while running my code

<div ng-model="activeFilterCtrl.selectedfilters" ng-repeat="filters in activeFilterCtrl.selectedfilters" ng-model-options="{trackBy: '$value.params'}" flex>
      <md-button name="mylabel" ng-click="activeFilterCtrl.clearvalue()">{{filters.params}}</md-button>
</div>

I keep getting this error.

 Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: filters in activeFilterCtrl.selectedfilters, Duplicate key: string:a, Duplicate value: a

Please provide the solution Following is the value of selected filter

selected filter value is [{"params":"min","value":5}, {"params":"max","value":30}]
6
  • because you have multiple same values in array Commented Jul 11, 2016 at 8:26
  • @Rakeschand what could be the solution Commented Jul 11, 2016 at 8:28
  • you can track by $index or any unique value Commented Jul 11, 2016 at 8:29
  • 1
    The message explicitly says "Use 'track by' expression to specify unique keys". Also this question has been asked many times before. Please search before asking. Commented Jul 11, 2016 at 8:30
  • 1
    Possible duplicate of Angular ng-repeat Error "Duplicates in a repeater are not allowed." Commented Jul 11, 2016 at 8:31

2 Answers 2

1

try with this

 ng-repeat="filters in activeFilterCtrl.selectedfilters track by $index"
Sign up to request clarification or add additional context in comments.

Comments

1

Try this Demo Link

HTML

<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link href="style.css" rel="stylesheet" />
    <script data-semver="1.4.9" src="https://code.angularjs.org/1.4.9/angular.js" data-require="[email protected]"></script>
    <script src="app.js"></script>
  </head>

  <body ng-app="plunker" ng-controller="MainCtrl as activeFilterCtrl">
  <div ng-model="activeFilterCtrl.selectedfilters" ng-repeat="filters in activeFilterCtrl.selectedfilters" ng-model-options="{trackBy: '$value.params'}" flex>
      <md-button name="mylabel" ng-click="activeFilterCtrl.clearvalue()">{{filters.params}}</md-button>
</div>
  </body>

</html>

JS

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  var vm = this;

  vm.selectedfilters = [{"params":"min","value":5}, {"params":"max","value":30}]
});

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.