3gwebtrain 3gwebtrain - 6 months ago 61
AngularJS Question

'ng-repeat' How to get the `unique` values

Using an array, I am trying to filter and show the

unique
information in the list. For that I use the
angular
inbuild
filter
method.

But I am getting error.

Here is my try ( I am filtering by
SubProjectName
)

<ul>
<li ng-repeat="project in projectNames |
unique: 'SubProjectName' ">{{project.SubProjectName}}</li>
</ul>


But I am getting an error.

Live Demo

Answer

AngularJS doesn't include a unique filter by default. You can use the one from angular-filter. Just include the JavaScript

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.8/angular-filter.min.js"></script>

and include the dependeny in your app:

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

Your code should work right away! I edited your Plunker so it works.

Comments