Search code examples
angularjsangularjs-ng-repeatangular-filters

'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>

Live Demo


Solution

  • 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.