0

I currently have an ng-modal I labelled as "myQuery." Right now, it has two filters that appear as such:

    <accordion-group heading="" ng-repeat="hungry_pets in Pets" | filter:{hungry:false} | filter:{name:myQuery}" ... >

I have been looking online to find a way to perform a filter such that whatever I put in the query, it returns a list of Pets that match (contains the sequence of letters) in any field. So, my current object has the following fields: 'name','owner','color','weight', and 'hungry'. Ideally, I would try something like what I found in this question that would appear something like:

    <accordion-group heading="" ng-repeat="hungry_pets in Pets" | filter:{hungry:false} | filter:({name:myQuery}||{owner:myQuery}||{color:myQuery}||{weight:myQuery})" ... >

or:

    <accordion-group heading="" ng-repeat="hungry_pets in Pets" | filter:{hungry:false} | filter:filterALL)" ... >

Is there a way to achieve this by reformatting the HTML tag above? If I were to write a function 'filterALL' so that I could just replace it with 'filter:filterALL', what would that look like?

Community
  • 1
  • 1

2 Answers2

1

Well, I know that this doesn't completely answer the question, but if any parameter is considered for searching, and not a set of specific ones, you can use '$' instead of a specific field.

    <accordion-group heading="" ng-repeat="hungry_pets in Pets" | filter:{hungry:false} | filter:{$:myQuery}" ... >
0

You can write custom filter like below:

JS:

app.filter('customFilter', function() {
  return function(arr, searchString){
      ....
  };
});

HTML:

<accordion-group heading="" ng-repeat="hungry_pets in Pets" | customFilter)" ... >
kukkuz
  • 41,512
  • 6
  • 59
  • 95
Vimalraj
  • 1
  • 1