F
F
Friend2016-10-14 10:28:48
Angular
Friend, 2016-10-14 10:28:48

How to set filter through checkbox by key in angularjs?

Found how to set a filter by key

<tr data-ng-repeat="hotel in hotels | filter:{'name':'Вася'} ">
Vasya is looking for, it works, but if I set it through the CheckBox
<tr data-ng-repeat="hotel in hotels | filter:{'name':e2} ">
 <input type="checkbox" data-ng-model='e2' data-ng-true-value='Вася' data-ng-false-value='' />
it doesn't look for anything.
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Friend, 2016-10-14
@Tiran_94

If you create your own filter, you can specify the key

app.filter('filterMaterials', function () {
  return function (materials, wood, plastic) {
     var filteredMaterials = [];
     for (var i = 0; i < materials.length; i++) {
          if (materials[i].type === wood || materials[i].type === plastic) {
          	filteredMaterials.push(materials[i]);
          }
     }
     return filteredMaterials;
  };
});

materials[i].type - the type key or materials[i]['type']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question