Asking for advice on how to iterate over an array using ng-repeat
and filter the contained objects based on a function property. Find more details in this Plunker link.
Let's say we have an object like this:
vm.show1 = function(){
return true;
};
var object1 = {label: 'Object1', show: vm.show1};
We would like to filter it like so:
<div ng-repeat="object in ctrl.objects | filter:{show:true}">{{object.label}}</div>
However, since vm.show1
is a function (and not equal to true
), the filtering doesn't work as expected. Is there a way to make the filter call the function and check its result, or do I need to create a custom filter?
Update: Wondering if this approach is even feasible. If Angular doesn't handle dirty-checking automatically, the filter might not recognize when the function needs to be reevaluated.