Here is my fiddle http://jsfiddle.net/7mcj04or/
I cannot get this thing to work, I am attempting to create a custom filter on the checkboxes that I have selected. Here is my code:
HTML:
<div ng-controller="AppCtrl">
<label class="item-input-wrapper">
<input type="text" placeholder="Search" ng-model="searchTerm">
</label>
<div ng-repeat="l in letter">
<input ng-model="letter" type="checkbox" ng-checked="exists(l,selected)" ng-click="toggle(l, selected)">Letter {{l}}
</div>
<div ng-repeat="name in names | filter: searchTerm">
<p>
{{name}}
</p>
</div>
<pre ng-bind="selected | json"></pre>
</div>
JS:
var app = angular.module('starter', []);
app.controller('AppCtrl', function ($scope, $http) {
$scope.searchTerm = '';
$scope.names = ['Jimmy','Farris','Lance', 'Joaquin', 'Henry'];
$scope.letter = ['L','E','Y', 'H', 'U'];
$scope.selected = [];
$scope.toggle = function (item, list) {
var idx = list.indexOf(item);
if (idx > -1) {
list.splice(idx, 1);
}
else {
list.push(item);
}
};
$scope.exists = function (item, list) {
return list.indexOf(item) > -1;
};
});
app.filter('selectedLetter', function () {
// filter to check array of elements
return function (selected) {
return selected;
}
});
I want my ng-repeat to look like this:
<div ng-repeat="name in names | filter: searchTerm">
<p>
{{name | selectedLetter}}
</p>
</div>
That custom selected filter I am attempting to write is not filtering on what ever checkbox I select. So when I selected Letter L I want Lance to show up etc.
Again here is my fiddle the search works, just not the custom filter.