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?
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.
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.
'!' 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With