I'm using AngularJS and it's great. I can't find it in the Documentation - What is the equivalent in Javascript to this AngularJS expression:
<div>{{ (myList| filter:mySearch).length }}</div>
Thanks for the help.
The filter() method creates a new array filled with elements that pass a test provided by a function. The filter() method does not execute the function for empty elements. The filter() method does not change the original array.
Lodash provides a reject function that does the exact opposite of filter.
The syntax of this method is provided below: $("selector"). filter(criteria, function(index)); The criteria parameter is set to select elements and the function(index) parameter is optional (exercised when a specific element is to be fetched from the selection using the index).
It's on Angular's filter documentation:
{{ filter_expression | filter:expression }}
$filter('filter')(array, expression)
In your case, it would look something like $filter('filter')(myList, mySearch)
.
As an alternative syntax you can also inject a filter directly, without going through the $filter
service. For example to inject filter
filter to your controller you could write:
MyCtrl = function($scope, filterFilter) { $scope.filtered = filterFilter(myArray, expression); }
A question very similar to How to use a filter in a controller?
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