ng-repeat :filter by single field

Tim Webster picture Tim Webster · Feb 6, 2013 · Viewed 815.7k times · Source

I have an array of products that I'm repeating over using ng-repeat and am using

<div ng-repeat="product in products | filter:by_colour"> 

to filter these products by colour. The filter is working but if the product name / description etc contains the colour then the product remains after the filter is applied.

How do I set the filter to only apply to the colour field of my array rather than every field?

Answer

bmleite picture bmleite · Feb 6, 2013

Specify the property (i.e. colour) where you want the filter to be applied:

<div ng-repeat="product in products | filter:{ colour: by_colour }">