angular ui - AngularUI for AngularJS counting the "uniqe" filter results -


i'm using angularui 'unique' filter show list of unique items. question how can count of number of items in each unique result?

e.g. set is:

colors = [ {name:'black', shade:'dark'}, {name:'white', shade:'light'}, {name:'red', shade:'dark'}, {name:'red', shade:'dark'}, {name:'yellow', shade:'light'} ] 

and in view:

<li ng-repeat="color in colors | unique:'name'">{{color.name}}</li> 

gives:

<li>black</li> <li>white</li> <li>red</li> <li>yellow</li> 

i wish show in view black count 1, red 2, etc..

thanks

i dont think filter can change base structure way. you'l have preproccess collection in controller

with lodash example

collection = [{name:'a'},{name:'b'},{name:'a'},{name:'c'}]; _.mapvalues(_.groupby(collection, 'name'), function(r) { return r.length; }); object {a: 2, b: 1, c: 1} 

then iterate collection in ng-repeat


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -