AngularJS ng-repeat unique is NOT working -


i'm trying print unique values of names i'm unable that.

html code:

<div ng-controller="myctrl">     <div><input type="text" ng-model="namefilter" placeholder="search..." /></div>     <p ng-repeat="contact in contacts | orderby: 'customer.name'| unique:'customer.name'">{{ contact.customer.name }}</p>   </div> 

js code:

var myapp = angular.module('myapp',[]);  function myctrl($scope) {     $scope.namefilter = '';     $scope.contacts = [         { id:1, customer: { name: 'foo', id: 10 } },         { id:2, customer: { name: 'bar', id: 20 } },         { id:3, customer: { name: 'foo', id: 10 } },         { id:4, customer: { name: 'bar', id: 20 } },         { id:5, customer: { name: 'baz', id: 30 } },         { id:5, customer: { name: 'tar', id: 30 } },         { id:5, customer: { name: 'got', id: 30 } },         { id:5, customer: { name: 'man', id: 30 } },         { id:5, customer: { name: 'baz', id: 30 } },     ];  } 

the jsfiddle here: http://jsfiddle.net/nvarun123/0tgl7u6e/73/

this code working if remove unique ng-repeat.

here go, used unique filter in angular ui directives, link in bottom. have made small change in directive implementing deep finding using string. details inside references.

here demo of filter.

jsfiddle demo

change made inside unique filter.

var extractvaluetocompare = function (item) {         if (angular.isobject(item) && angular.isstring(filteron)) {           return deepfind(item,filteron);         } else {           return item;         }       }; 

as seen above implementing deepfind function. function provided below.

function deepfind(obj, path) {   var paths = path.split('.')     , current = obj     , i;    (i = 0; < paths.length; ++i) {     if (current[paths[i]] == undefined) {       return undefined;     } else {       current = current[paths[i]];     }   }   return current; } 

references:

  1. angular-ui unique filter

  2. javascript deep value passing path


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -