javascript - AngularJS: filter by inner array object field -


i have following data:

organizations:[{                 name: "foo",                 contacts: [{                              firstname = "john",                              lastname = "doe",                              email = "john.doe@email.com"                           },...]                },...] 

then have table list organizations , want know if possible filter rows in table according firstname filter or email filter.

for example have code:

<input type="text" id="name" ng-model="search.name">  <tr ng-repeat="organization in organizations | filter:search">     <td>{{organization.name}}</td>     <td>{{client.contacts[0].firstname}} {{ client.contacts[0].lastname }}</td>     <td>{{client.contacts[0].email}}</td> </tr> 

it works filtering 'name' field. tried this:

<input type="text" id="firstname" ng-model="search.contacts"> 

but searches in fields of objects in contacts array, want search firstname. how can do?

use filter function filter:filterby.

example (relies on underscore.js):

scope.filterby = function(row) {     return !!_.where(row.contacts, {firstname:scope.search.name}).length; } 

Comments