0

enter code hereI have an ng-repeat in my ionic code. It gives me many duplicate values as the data is coming from CSV file. How can I stop this duplicate values from being shown ? Data shows XYZ values more than 5 times but I want it to be shown only once.

      <select ng-model="srcstn">
        <option   ng-repeat="x in from track by $index " >{{x.source}}</option>
      </select>

This is piece of code where m getting all duplicate values at {{x.source}}. and x.source has station names

Aniket
  • 27
  • 4
  • 1
    Can't you just filter out the duplicates before displaying the data? – yadejo Mar 21 '18 at 11:40
  • Possible duplicate of [How to make ng-repeat filter out duplicate results](https://stackoverflow.com/questions/15914658/how-to-make-ng-repeat-filter-out-duplicate-results) – Aleksey Solovey Mar 21 '18 at 11:52
  • @yadejo I would have done that but this is a client side data that m getting using API and I will not be able to change it because same is being used throughout the App for different features. – Aniket Mar 21 '18 at 11:53
  • @Aniket can you please post your data and the criteria you want to filter on the basis of ? – Muhammad Usman Mar 21 '18 at 12:03
  • @UsmanRana Sir, Data is in form of JSON string. Lets say I have 3 stations WFD,BLD,BNC. They will come in my select tag almost 5-6 times each. I just want them to come once. And I updated bit of a code there. – Aniket Mar 21 '18 at 12:13
  • Ok. why don't you make a copy of this data and deal with it ? like `var copy = angular.copy($scope.from)` – Muhammad Usman Mar 21 '18 at 12:15
  • I worked on it and its solved. Thanks everyone. – Aniket Mar 21 '18 at 16:26

1 Answers1

1

Try using 'unique'(aliases: uniq) filter in angular.filter module

usage: colection | uniq: 'property' 

you can also filter by nested properties:

 colection | uniq: 'property.nested_property'

try

<select ng-model="srcstn">
        <option   ng-repeat="x in from |uniq:'source'" >{{x.source}}</option>
      </select>
Neha Tawar
  • 687
  • 7
  • 23