1

I'm trying to use filter to exclude an item from a list using the filter:object method. What am I doing wrong?

 <div ng-init="itemList = [
{ id: 'item1', name: 'item 1' },
{ id: 'item2', name: 'item 2' },
{ id: 'item3', name: 'item 3' } ];test='item2';">
  <ul>
    <li ng-repeat="item in itemList | filter:{ id: '!{{ test }}' }">{{ item.name }}</li>
  </ul>
</div>

Here's the Plunker

1 Answer 1

2

You don't need curly brackets inside angular expression. Also since test is a variable, not actual value to negate you need to concatenate it with the string ! to get final filter condition.

It will be:

<li ng-repeat="item in itemList | filter:{ id: '!' + test }">{{ item.name }}</li>

Demo: http://plnkr.co/edit/vowrYe3aHLrmwmb1ounK?p=info

Sign up to request clarification or add additional context in comments.

Comments

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.