Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

Let say I have an array object

[{
    name: 'a',
    number: 1
},
{
    name: 'b',
    number: 2
},
{
    name: 'c',
    number: 3
}]

And I just want to get the name:'b' which is array[1] values. How to pass it to the filter?

<li ng-repeat="foo in foos | filter:what_to_do_here="b"><li>
share|improve this question

2 Answers 2

up vote 20 down vote accepted
<li ng-repeat="foo in foos | filter:{name:'b'}">{{foo.name}}</li>
share|improve this answer
1  
suppose there's another object in the list {name:'abc',number:100}, then this filter will also select this object because it contains b in name attributes. is there anyway to alter the comparison behavior from 'contains' to exact match? – Bilal Mirza Sep 12 '13 at 11:04
1  
See if this helps: stackoverflow.com/a/18243147/1095616 – Stewie Sep 12 '13 at 15:58
    
Thanks @Stewie, I've just resolved it in same way. – Bilal Mirza Sep 13 '13 at 6:12
    
Is there anyway to apply a not filter to this? For example, all objects whose name is not 'b'? – Conqueror Nov 7 '13 at 22:19
    
Yes, prepend the search string with !: <li ng-repeat="foo in foos | filter:{name:'!b'}">{{foo.name}}</li>. Btw, this filters out those items which contain letter "b". For the exact match filtering see the comment link above. – Stewie Nov 8 '13 at 10:07
<li ng-repeat="foo in foos | filter:'b'">{{foo.name}}</li>

might work as well

share|improve this answer
    
Sure, but vzhen wants to filter by name explicitly. – Stewie Apr 2 '13 at 12:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.