ngRepeat Filter by deep property

ExceptionLimeCat picture ExceptionLimeCat · Dec 22, 2014 · Viewed 55.6k times · Source

If I have a complex object with objects as property values, how can I filter by one of the nested properties?

Can this be done with the OOB ng-repeat filter?

Data

{
  Name: 'John Smith',
  Manager: {
     id: 123,
     Name: 'Bill Lumburg'
  }
}

ngRepeat

<li ng-repeat="e in emps | filter:Manager.Name">{{ e.Name }}</li>

Answer

Ray picture Ray · Oct 7, 2015

You need to pass in the argument to filter by:

<input ng-model="filter.key">
<ul>
  <li ng-repeat="e in list | filter: {Manager: {Name: filter.key}}">
    {{e.Name}}  (Manager: {{e.Manager.Name}})
  </li>
</ul>

Example on Plunker