0

I have a simple problem that I can't find any answers to on Stack.

I have data, like so:

$scope.data = [
{name: 'foo', age: 19, job:'bartender', city: 'someplace'}
{name: 'foo', age: 20, job:'something else', city: 'someplace'}
{name: 'foo', age: 21, job:'another thing', city: 'someplace'}
]

You get the idea (except the actual dataset is 1000x this and have 50 properties - the API is read only so I'm stuck with what I've got!).

My ng-repeat builds a table from this data, and I have an input allowing the user to filter.

Let's say I only want the input to filter the name and city fields. (in real-world use, this will be about 10 fields). How do I do it?

I've seen things like:

<input ng-model="filterBy.property">
<div ng-repeat="item in data | filter: filterBy">

But this won't work for multiple, selective properties.

JVG
  • 20,198
  • 47
  • 132
  • 210

1 Answers1

0

Maybe this will help you

<input ng-model="filterBy.name">
<input ng-model="filterBy.city">
<div ng-repeat="item in data | filter:{name: filterBy.name, city: filterBy.city}"></div>
Rajesh Patel
  • 1,946
  • 16
  • 20