9

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>
vzhen
  • 11,137
  • 13
  • 56
  • 87

2 Answers2

20
<li ng-repeat="foo in foos | filter:{name:'b'}">{{foo.name}}</li>
Stewie
  • 60,366
  • 20
  • 146
  • 113
  • 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
  • Is there anyway to apply a not filter to this? For example, all objects whose name is not 'b'? – Conqueror Nov 07 '13 at 22:19
  • Yes, prepend the search string with `!`: `
  • {{foo.name}}
  • `. Btw, this filters out those items which **contain** letter "b". For the exact match filtering see the comment link above. – Stewie Nov 08 '13 at 10:07