How does filter work in AngularJS?

angularjs, angularjs-ng-repeat

Solution

`email` works because nested property `address` doesn't contain any `$` char.

Unfortunately, I don't think there is a way to bypass this behavior, however you can make your own filter and use it in `ng-repeat`.

This is simple example that should work for you:

JS

app.filter('customFilter', function() {
  return function(items, keyword) {
    if (!keyword || keyword.length === 0) return items;

    return items.filter(function(item){
      var phrase = keyword.$.toLowerCase();
      return item.gd$name.gd$fullName.$t.toLowerCase().includes(phrase) || 
        item.gd$name.gd$familyName.$t.toLowerCase().includes(phrase) || 
        item.gd$name.gd$givenName.$t.toLowerCase().includes(phrase) ||
        item.gd$email[0].address.toLowerCase().includes(phrase) ||
        item.gd$phoneNumber[0].$t.toLowerCase().includes(phrase) ||
        (!!item.gd$organization[0].gd$orgTitle && item.gd$organization[0].gd$orgTitle.$t.toLowerCase().includes(phrase)) ||
        (!!item.gd$organization[0].gd$orgName && item.gd$organization[0].gd$orgName.$t.toLowerCase().includes(phrase));
    });
  }
});

HTML

<tr ng-repeat="x in obj | customFilter:searchText">

Of course, you will have to add more checks for possible `null` values. I've just wanted to make it work on the data you've provided.

Hope, you'll find it useful.

Here's plunk

Problem

I have a table generated with `ng-repeat` (from an objects' array). I would like to filter it with a search text field. Objects contained in my array has got deep properties. I don't know why and how, but the filter is only working on email field, which is as deep as other properties. I'm using this search form : ``` <input type="text" name="search" ng-model="searchText" /> ... <tr ng-repeat="x in obj | filter:searchText track by $index"> ... </tr> ``` plunker EDIT : This answer helps me to understand why it's not working. Someone knows how I can bypass the $ verification in filter ? I'm using $ because I'm following the Google Contact API format.

Original source