Angularjs filter nested object

zajca picture zajca · Aug 29, 2013 · Viewed 30.8k times · Source

I have in angular nested object like this. is there way how to filter it for nested property

<li ng-repeat="shop in shops | filter:search">
search.locations.city_id = 22

I'm showing only parent element but want to filter by both of it, like:

search = 
  category_id: 2
  locations:
    city_id: 368

[
 name: "xxx"
 category_id: 1
 locations: [
   city_id: 368
   region_id: 4
  ,
   city_id: 368
   region_id: 4
  ,
   city_id: 368
   region_id: 4
  ]
,
 name: "xxx"
 category_id: 2
 locations: [
   city_id: 30
   region_id: 4
  ,
   city_id: 22
   region_id: 2
  ]
]

Answer

martinoss picture martinoss · May 31, 2014

You also can filter like this (version 1.2.13+)

<li ng-repeat="shop in shops | filter: { locations: [{ city_id: search.locations.city_id }] }">