ExceptionLimeCat ExceptionLimeCat - 2 months ago 10
Javascript Question

ngRepeat Filter by deep property

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>

Ray Ray
Answer

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

Comments