0

I'm trying to filter items by field when check is actived buy I get an error.

<input type="checkbox" ng-model="filterActive">
<input type="text" ng-model="reftext"/>
<input type="text" ng-model="nametext"/>


<tr ng-repeat="car in cars.items | togglableFilter:{reference:reftext, name:nametext}:filterActive">

</tr>


.filter('togglableFilter',[function(){
    return function(input, filterText, isFilterActive){

      if(!angular.isDefined(isFilterActive) || !isFilterActive) return input;
      var ret = input;
      var col = [];
      var isDefined = false;

      var key = Object.keys(filterText);

      for (var i = 0; i < key.length; i++) {

        if(angular.isDefined(filterText[key[i]])) {
          isDefined = true;
          angular.forEach(input, function (v) {
            if (v[key[i]].indexOf(filterText[key[i]]) !== -1) {
              col.push(v);
            }
          });
        }
      }

      if (isDefined) return col; else return input;
    }
  }]);

Error: [ngRepeat:dupes] errors.angularjs.org/1.2.13/ngRepeat/dupes?p0=car%20in%20cars.items%20%7C%20togglableFilter%3A%7Breference%3Areftext%2C

2
  • 1
    The error is telling you to look at this: docs.angularjs.org/error/ngRepeat/…, It would seem that your filter is returning multiple references to the same items. Commented Mar 16, 2015 at 8:44
  • 1
    cars.items has duplicate entries in it so angular is not able to associate a unique key with the DOM element created.if you see the error details in the URL given above you can see that the solution is to use track by $index. Commented Mar 16, 2015 at 8:48

1 Answer 1

0

cars.items has duplicate entries in it so angular is not able to associate a unique key with the DOM element created.if you see the error details in the URL given above you can see that the solution is to use track by $index so that using the $index unique value angularJS can track the association between models and DOM

 <tr ng-repeat="car in cars.items  track by $index | togglableFilter:{reference:reftext, name:nametext}:filterActive">

if you have some difficulty in filtering the data try using

 <tr ng-repeat="car in cars.items   | togglableFilter:{reference:reftext, name:nametext}:filterActive track by $index">

Sign up to request clarification or add additional context in comments.

4 Comments

If i add the next line <tr ng-repeat="car in cars.items | togglableFilter:{reference:reftext, name:nametext}:filterActive track by $index"> duplicate cars info when I filter with both filters
@AgustínCastro what are you trying to do with that filter?
filter by column when checkbox is actived. I have a lot of input that you can filter by property
duplicate the result numers when I filter with two o more inputs. for example, if i have two result and i try to filter with two inputs i will get 4 results. but, i i try to filter with one inputs i will get two

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.