1

Say i have the following array

$scope.myArr = [{
    name: 'Marc Rasmussen',
    phone: 239470192,
    title: 'It Dude',
    description: 'Hello my name is Marc i am testing the fact that i can search for two fields in an object'
}, {
    name: 'Louise',
    phone: 1234567890,
    title: 'HR Director',
    description: 'I am also testing'
}, {
    name: 'Leonardo',
    phone: 123499,
    title: 'Actor',
    description: 'I have never won an oscar'
}];

Now as you can see i have the following fields:

  • name
  • phone
  • title
  • description

Now i repeat these using ng-repeat

<div ng-repeat="obj in myArr">
    <div>
        name: {{obj.name}}
    </div> 
    <div>
        phone: {{obj.phone}}
    </div>
    <div>
        title: {{obj.title}}
    </div>
    <div>
       description: {{obj.description}}
    </div>
</div>

Now what i want is that i want a single textfield to search for results in both the name and description and no other field

Normally you would care a variable such as $scope.search.$ but this would search in all fields. alternativly you could make an input field for each field however this does not forfill what i wish to accomplish.

So my question is how can you make 1 input search for two fields at the same time?

here is a fiddle of the above code:

Fiddle

John Slegers
  • 45,213
  • 22
  • 199
  • 169
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364

1 Answers1

0

I believe this article might help you out: Filtering by Multiple Specific Model Properties in AngularJS (in OR relationship)

Essentially taking advantage of angular's filter and using a predicate function on each item in the repeated array.

Community
  • 1
  • 1
Josh
  • 403
  • 7
  • 12