I am trying to write a custom filter. It's purpose is to do one of three things, based on a drop down menu. It needs to either show only hidden items, only notHidden items, or all items.
Here is my drop down menu.
<select class="span1" ng-model="itemfilter.hidden'">
<option value="">All</option>
<option value="hidden">Hidden</option>
<option value="shown">Shown</option>
</select>
Here is the HTML for the ng-repeat and filter
<div ng-repeat="item in items | hiddenFilter:itemfilter.hidden:'hidden"> </div>
Here is the Custom Filter
app.filter('hiddenFilter', function($_ ) {
return function( items, show_or_hide, attribute ) {
var shownItems = [];
$_.each(items, function(item) {
if(show_or_hide === 'shown') {
if (item[attribute] === true)
shownItems.push(item);
} else{
if (item[attribute] !== true)
shownItems.push(item);
}
});
return shownItems;
};
});
I am having trouble figuring out how to make the drop down menu change what this filter displays, any help would be greatly appreciated.
Edits -- Once I passed in the attribute correctly I started getting different results. The all and hidden options now show only nonHidden items, and the shown options shows only hidden items. Still not sure where I am going wrong.
Edit 2 -- Tried to make a jsfiddle for it here http://jsfiddle.net/mindstormy/RVB8A/1/