i have checkbox list use filter list. checkbox list hard codes , looks this:
<input type="checkbox" ng-model="characteristics.nontraditional" ng-true-value="non-tradtional" ng-false-value="">  non traditional<br> <input type="checkbox" ng-model="characteristics.metal" ng-true-value="metal" ng-false-value="">  metal<br> <input type="checkbox" ng-model="characteristics.plancha" ng-true-value="plancha" ng-false-value="">  plancha<br> <input type="checkbox" ng-model="characteristics.rocket" ng-true-value="rocket" ng-false-value="">  rocket<br> <input type="checkbox" ng-model="characteristics.wick" ng-true-value="wick" ng-false-value="">  wick
i have ng-repeat looking this:
<div ng-repeat="stove in stoves | filteredstoves:characteristics">
and custom filter looking this:
stovecat.filter('filteredstoves', function() { return function(stoves, characteristics) { alert(characteristics) } } }
when load page. alert contains "undefined" expected no checkbox has been selected. when select 1 or more checkboxes, alert contains [object object], fine object passed custom filter. how access these values passed custom filter can filter list accordingly? there i'm missing?
thanks folks!
plunker solution: http://plnkr.co/edit/7phneadhw099w9kaqs7m?p=preview
template:
<input type="checkbox" ng-model="characteristics.nontraditional">  non traditional</input><br> <input type="checkbox" ng-model="characteristics.metal">  metal</input><br> <input type="checkbox" ng-model="characteristics.plancha">  plancha</input><br> <input type="checkbox" ng-model="characteristics.rocket">  rocket</input><br> <input type="checkbox" ng-model="characteristics.wick">  wick</input><br/> <div ng-repeat="stove in stoves | filteredstoves:characteristics">{{stove.name}} - {{stove.characteristics}}</div>
filter:
stovecat.filter('filteredstoves', function() { return function(stoves, characteristics) { var result = stoves.slice(); // copy array angular.foreach(characteristics, function(value, key) { if(value) { for(var index = 0; index < result.length; index++) { stove = result[index]; if(stove.characteristics.indexof(key) == -1) { result.splice(index--,1); } } } }); return result; } });
just go through characteristics in filter , remove items without them
Comments
Post a Comment