Search - filter just for fore- and surname

Hey guys,

i have here some data and want to filter the data.
Today i could filter it by a input-field (filter: search).
But this is searching in all values of the data, i just want to search just in the forename and surname.

<ion-item ng-repeat="group in groups | filter:search" class="item-remove-animate item-icon-right">

By default you can only search through all object-properties or just one
Look at the example:

If you want a custom search you can create your own filter or define an own filter function:
Look at the last code-example (“Discussion”-part)

1 Like

Okay, the second link is good.
But it is still not 100 % what i need.

ng-repeat="friend in friends | filter: { name: query, age: '20' } | orderBy: 'name'

It filters every entry with age=20 and the searchinput. But i need it to search for the value XYZ in “name” as well as in “age”. But with:

ng-repeat="friend in friends | filter: { name: query, age: query } | orderBy: 'name'

It is searching in both fields and showing no result.

You’re looking for an OR search, rather than an AND search. You will need to create a custom filter for that.

app.filter('friends', function () {
    return function (items, text) {
        return items.filter(function (item) {
            var exp = new RegExp(text, 'i');
            return exp.test( || exp.test(item.age);

You can call this in your HTML or you can inject it in your controller as friendsFilter

1 Like

I found an very easy way to implement search functionality in Ionic and Angular, checkout:

1 Like