5

Might be missing some simple syntax, but I can't seem to get not equal filter to work:

I can do

filter: {property:{text:'yes'}},

but not

filter: {property:{text:'!yes'}},

which does work for non-nested objects.

HTML:

<ul>
  <li ng-repeat="attr in attributes | filter: {property:{text:'!yes'}}">
    {{attr.property.text}}
  </li>
</ul>

JS:

$scope.attributes = [
  {property: { text:'yes' }},
  {property: { text:'no' }},
];

Plunkr link:

http://plnkr.co/edit/2mTcQijmfnqAM5vUtKsK?p=preview

2 Answers 2

6

You can get the same effect with ng-if like this:

<ul>
    <li ng-repeat="attr in attributes" ng-if="attr.property.text !== 'yes'">
        {{attr.property.text}}
    </li>
</ul>

Alternatively you could write a custom filter that contains the logic or flatten the original structure somehow. I don't think ! is supported in nested structures.

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

2 Comments

I don't know if it's a new feature, but there is a way to use ! with nested structures. Posted another answer with it
Ok, maybe they have fixed it then. Nice!
4

You could use

filter: !{property:{text:'yes'}}

This is usefull in situations where you can't use ng-if like

<select ng-options="element in elementList | filter: !{property: {text:'yes'} }" />

(I know you can use ng-repeat in the options, but you get my point...)

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.