arrays - AngularJS custom filter function -
inside controller, filter array of objects. each of these objects map can contain strings lists
i tried using $filter('filter')(array, function)
format not know how access individual elements of array inside function. here snippet show want.
$filter('filter')(array, function() { return criteriamatch(item, criteria); });
and in criteriamatch()
, check if each of individual property matches
var criteriamatch = function(item, criteria) { // go thro each individual property in item , criteria // , check if equal }
i have these in controller , compile list of lists , set them in scope. need access $filter('filter')
way only. examples found in net far have static criteria searches inside function, don't pass criteria object , test against each item in array.
you can use this: http://plnkr.co/edit/vtnjegmpitqxx5fdwtpi?p=preview
like found, filter
accepts predicate function accepts item item array. so, have create predicate function based on given criteria
.
in example, criteriamatch
function returns predicate function matches given criteria
.
template:
<div ng-repeat="item in items | filter:criteriamatch(criteria)"> {{ item }} </div>
scope:
$scope.criteriamatch = function( criteria ) { return function( item ) { return item.name === criteria.name; }; };
Comments
Post a Comment