0

I use this filter in my AngularJS application and now I need also to filter or firstname. Currently my filter looks like this:

| filter: {user: {surname: searchEmployeesText}}

Is there a possibility to filter also of firstname without a filter function?

quma
  • 5,233
  • 26
  • 80
  • 146
  • Possible duplicate of [Filtering by Multiple Specific Model Properties in AngularJS (in OR relationship)](http://stackoverflow.com/questions/13216115/filtering-by-multiple-specific-model-properties-in-angularjs-in-or-relationship) – Mitch Lillie Dec 05 '16 at 22:08

1 Answers1

0

Create your custom filter gives you more flexibility,

HTML

<li ng-repeat="user in users | filter:isExists(searchText)">First :  {{user.name}} || Last : {{user.lname}}</li>

JS here i am searching entered searchText in fname as well as in lname.

$scope.isExists = function (searchText) {
        return function (user) {
            return (!searchText || (user.lname.indexOf(searchText) > -1) || (user.name.indexOf(searchText) > -1));
        }
    };

DEMO

user3249448
  • 1,369
  • 2
  • 14
  • 34