I want to use the filter
in angular and want to filter for multiple values, if it has either one of the values then it should be displayed.
I have for example this structure:
An object movie
which has the property genres
and I want to filter for Action
and Comedy
.
I know I can do filter:({genres: 'Action'} || {genres: 'Comedy'})
, but what to do if I want to filter it dynamically. E.g. filter: variableX
How do I set variableX
in the $scope
, when I have an array of the genres I have to filter?
I could construct it as a string and then do an eval()
but I don't want to use eval()...
Here is my example how create filter and directive for table jsfiddle
directive get list (datas) and create table with filters
my pleasure if i help you
I believe this is what you're looking for:
If you want to filter on Array of Objects then you can give
filter:({genres: 'Action', key :value }.
Individual property will be filtered by particular filter given for that property.
But if you wanted to something like filter by individual Property and filter globally for all properties then you can do something like this.
~Atul
Lets assume you have two array, one for movie and one for genre
Just use the filter as:
filter:{genres: genres.type}
Here genres being the array and type has value for genre
You can use a controller function to filter.
HTML:
The quickest solution that I've found is to use the
filterBy
filter from angular-filter, for example:The upside is that angular-filter is a fairly popular library (~2.6k stars on GitHub) which is still actively developed and maintained, so it should be fine to add it to your project as a dependency.