Angular JS filter is not equal

Sounds like a very simple question, but I can't get the syntax correctly.

<li class="list-group-item" ng-repeat="question in newSection.Questions | filter:Id != '-1'; " ng-mouseenter="hover = true" ng-mouseleave="hover = false"> <div href="#" editable-text="question.Text">{{question.Text}}</div> </li> 

All I want is to show all questions where id is not equal to -1. What am I doing wrong. Thank!

+62
javascript angularjs angularjs-ng-repeat ng-filter
Mar 26 '14 at 15:50
source share
2 answers

The syntax does not work a bit, try:

 <li class="list-group-item" ng-repeat="question in newSection.Questions | filter:{ Id: '!-1'}" ng-mouseenter="hover = true" ng-mouseleave="hover = false"> <div href="#" editable-text="question.Text">{{question.Text}}</div> </li> 

Take a look at a bit of JSFiddle: http://jsfiddle.net/U3pVM/3845/

Edit:

Example with variables:

 <script> var invalidId = '-1'; </script> <li class="list-group-item" ng-repeat="question in newSection.Questions | filter:{ Id: '!' + invalidId}" ng-mouseenter="hover = true" ng-mouseleave="hover = false"> <div href="#" editable-text="question.Text">{{question.Text}}</div> </li> 
+130
Mar 26 '14 at 16:02
source share

Although @Michael Rose's answer works for this case, I donโ€™t think it would be if you try to filter non-equal any object / variable

In this case you can use:

Js

 filterId = -1 

HTML:

 <li ng-repeat="question in newSection.Questions | filter: !{ Id: filterId}"> </li> 



An even more nested case:

Js

 someQuestion = { someObject: { Id: 1 } } newSection.Questions = [someQuestion] 

HTML

 <li ng-repeat="question in newSection.Questions | filter: !{someObject : {Id: -1} }"> </li> 
+17
Jan 28 '15 at 17:16
source share



All Articles