Ng-repeat filter based on search input

I have the following html:

  <div>
    <div>
      <input type="text" placeholder="Search" ng-model="userSearch.firstname">
    </div>
  </div>

 <div>
   <div ng-repeat="user in users | filter:userSearch ">
     <div>
       {{user.firstname}} {{user.lastname}}
     </div>
   </div>
 </div>

So, I have an input field in which users can enter and search all users in my list. Is there a way to apply an inline filter in ng-repeat based on what the user enters into the search input?

The current solution filters only the first name

I would like to filter out both the first and last name

I tried:

  <div>
    <div>
      <input type="text" placeholder="Search" ng-model="userSearch">
    </div>
  </div>

 <div>
   <div ng-repeat="user in users | filter:{firstname: userSearch, lastname: userSearch} ">
     <div>
       {{user.firstname}} {{user.lastname}}
     </div>
   </div>
 </div>

But I think this is AND not an or.

+4
source share
1 answer

Change the ng model from userSearch.firstnameto userSearch.

 <input type="text" placeholder="Search" ng-model="userSearch">

http://jsbin.com/keyuno/1/edit?html,js,output

filter:userSearch filter:userSearch.firstname. , .

+10

All Articles