0

I am using "itunes-search" module in nodejs and it is send the sends the search results as Json data. The Json data has a filed named "artistName" which has duplicates element I can see. but I want to print the "artistName" values discarding the duplicates instance. Means one value should be printed only one time. I have only included the

<script type="text/javascript" src="/angular.js"></script>
<script src="js/angular-file-upload.min.js"></script> 

I am trying with the bellowed code. But it is not working. Multiple elements of value are also printed.

<ul>
<li data-ng-repeat="data in response | orderBy:'artistName' | unique:'artistName' "> 
<b> {{data.artistName}} <b><br/>
</li>
</ul>

I will really appreciate him who will help me.

Muhammad Ashikuzzaman
  • 3,075
  • 6
  • 29
  • 53

2 Answers2

0

You'll need to create your filter. Here is an example :

angular.module('app',[]).filter('unique', function() {
  return function(list, attribute) {
    var result= [];
    var keys = [];

    // Find duplicates
    angular.forEach(list, function(item) {
      if(keys.indexOf(item[attribute]) === -1) { // Not already present
          keys.push(item[attribute]);
          result.push(item);
      }
  });

  return result;
};
Michael Laffargue
  • 10,116
  • 6
  • 42
  • 76
0

The error says you need to have unique filter loaded in your angular app in order to use it. Angular could not find the filter and hence throwing the error. Here is the way you can fix that.

  1. Save this as unique.js in your scripts and load it in HTML.
  2. Add 'ui.filters' to your dependencies in your app.
Jayram
  • 18,820
  • 6
  • 51
  • 68