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?
Specify the property (i.e.
colour
) where you want the filter to be applied:See the example on the filter page. Use an object, and set the color in the color property:
If you want to filter on a grandchild (or deeper) of the given object, you can continue to build out your object hierarchy. For example, if you want to filter on 'thing.properties.title', you can do the following:
You can also filter on multiple properties of an object just by adding them to your filter object:
Specify the property in filter, of object on which you want to apply filter:
But you want to apply filter only on firstname
Be careful with angular filter. If you want select specific value in field, you can't use filter.
Example:
javascript
html
This will select both, because use something like
substr
That means you want select product where "color" contains string "blue" and not where "color" is "blue".
You can filter by an object with a property matching the objects you have to filter on it:
This can of course be passed in by variable, as Mark Rajcok suggested.