filtering - Using filters in angularjs with hardcoded checkboxes -


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="">&#160; non traditional<br> <input type="checkbox" ng-model="characteristics.metal" ng-true-value="metal" ng-false-value="">&#160; metal<br> <input type="checkbox" ng-model="characteristics.plancha" ng-true-value="plancha" ng-false-value="">&#160; plancha<br> <input type="checkbox" ng-model="characteristics.rocket" ng-true-value="rocket" ng-false-value="">&#160; rocket<br> <input type="checkbox" ng-model="characteristics.wick" ng-true-value="wick" ng-false-value="">&#160; 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">&#160; non traditional</input><br> <input type="checkbox" ng-model="characteristics.metal">&#160; metal</input><br> <input type="checkbox" ng-model="characteristics.plancha">&#160; plancha</input><br> <input type="checkbox" ng-model="characteristics.rocket">&#160; rocket</input><br> <input type="checkbox" ng-model="characteristics.wick">&#160; 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