Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS filter not equals

Seems like a very basic question but I can't get the syntax right..

<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 the questions where id is NOT -1. What am I doing wrong. Thanks!

like image 902
americanslon Avatar asked Mar 26 '14 15:03

americanslon


People also ask

What is not a filter in AngularJS?

Option C is not a valid AngularJs Filter. Filters are used to change modify the data and can be clubbed in expression or directives using pipe character. Filters can be added to expressions by using the pipe character |, followed by a filter. AngularJS provides filters to transform data.

How does filter work in AngularJS?

The “filter” Filter in AngularJS is used to filter the array and object elements and return the filtered items. In other words, this filter selects a subset (a smaller array containing elements that meet the filter criteria) of an array from the original array.


1 Answers

The syntax is just a little off, 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> 

See a little 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> 
like image 137
Michael Rose Avatar answered Sep 18 '22 18:09

Michael Rose