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>

2 Answers 2

20
<li ng-repeat="foo in foos | filter:{name:'b'}">{{foo.name}}</li>
Sign up to request clarification or add additional context in comments.

3 Comments

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?
Is there anyway to apply a not filter to this? For example, all objects whose name is not 'b'?
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.
1
<li ng-repeat="foo in foos | filter:'b'">{{foo.name}}</li>

might work as well

1 Comment

Sure, but vzhen wants to filter by name explicitly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.