Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs filter negated

Tags:

I have a set of items that I want to filter in ng-repeat using an ng-model as the string to filter the set, so far I haven't found a way to make it work when the expression is negated, I'm doing something like this:

<select ng-model="languageOrigin" ng-change="updatePrice()">              <option ng-repeat="language in languages">{{language}}</option> </select> <select ng-model="languageDestination" ng-change="updatePrice()">             <option ng-repeat="language in languages | filter:!languageOrigin">{{language}}</option> </select> 

In the documentation, it says that we should use ! to negate the expression but still no luck.

What am I doing wrong?

like image 732
lgomezma Avatar asked Nov 07 '12 21:11

lgomezma


People also ask

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.

How do I filter in NG repeat?

The ng-repeat values can be filtered according to the ng-model in AngularJS by using the value of the input field as an expression in a filter. We can set the ng-model directive on an input field to filter ng-repeat values.


1 Answers

'!' character prepend to the filter string, like below:

filter:'!'+languageOrigin

<select ng-model="languageOrigin" ng-change="updatePrice()">   <option ng-repeat="language in languages">{{language}}</option> </select> <select ng-model="languageDestination" ng-change="updatePrice()">   <option ng-repeat="language in languages | filter:'!'+languageOrigin">{{language}}</option> </select> 
like image 189
ENDOH takanao Avatar answered Sep 24 '22 09:09

ENDOH takanao