1

I have a set of data like this

$scope.students = [
   { name:"John", courses:["Math", "Physics", "Chemistry"] },
   { name:"Paul", courses:["Economics", "Math", "Sociology"] }
]

I would like a way to filter using angular-filter so that I can get a list of all the subjects without repetition. I've been trying to use unique filter, but I cannot get it to work since I try to iterate like

<ul ng-repeat="student in students">
   <li ng-repeat="x in student.courses | unique:courses"></li>
       {{x}}
</ul>

My desired output of the first ng-repeat would be an array like this:

["Math", "Physics", "Chemistry", "Economics", "Sociology"]

so I could iterate through it in the second one.

I have achieved this throught making a new scope with just the desired array, but then I cannot bind it properly, so I would like to achieve it through filtering. Thanks in advance.

Joe82
  • 1,357
  • 2
  • 24
  • 40
  • Possible duplicate of [How to make ng-repeat filter out duplicate results](http://stackoverflow.com/questions/15914658/how-to-make-ng-repeat-filter-out-duplicate-results) – martin Feb 28 '16 at 23:33
  • You can use the library: https://github.com/angular-ui/angular-ui/blob/master/modules/filters/unique/unique.js. Btw, `ng-repeat` must be used exclusively in the `
  • ` tag and not the `
      `.
  • – developer033 Feb 29 '16 at 01:25
  • @Martin, it is not the same case, as I unique:courses doesn't work if courses refers to an array – Joe82 Feb 29 '16 at 09:05
  • @developer033, yes, that's exactly what I want to use, but I don't know how to achieve that :) – Joe82 Feb 29 '16 at 09:06