javascript - angularJS filter expression in ng-repeat -
i know elegant , simple way implement this. need add filter expression ng-repeat filter 2 conditions 1 property.
in example http://plnkr.co/edit/omqxxvsjtuudmrge4ez8?p=preview
- if enter a, display checkbox a,
- enter b - display checkbox b.
but want display specified checkboxes plus empty condition. there no condition c, so:
- if enter a, want display both , c checkboxes,
- enter b, want display both b , c checkboxes.
i create custom filter like:
app.filter('myfilter', function() { return function( items, condition) { var filtered = []; if(condition === undefined || condition === ''){ return items; } angular.foreach(items, function(item) { if(condition === item.condition || item.condition === ''){ filtered.push(item); } }); return filtered; }; });
and usage:
<span ng-repeat="charge in charges | myfilter:level.condition">
see demo in plunker
it looks pretty elegant , clear.
hope
Comments
Post a Comment