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?
my way is this
Displaying like this
If you were to do the following:
...you would not only get items of itemTypeId 2 and itemStatus 1, but you would also get items with itemType 20, 22, 202, 123 and itemStatus 10, 11, 101, 123. This is because the filter: {...} syntax works like a string contains query.
However, if you were to add the : true condition, it would do filter by exact match:
If you want filter for one field:
If you want filter for all field:
and https://docs.angularjs.org/api/ng/filter/filter good for you
Best way to do this is to use a function:
html
javascript
Alternatively, you can use ngHide or ngShow to dynamically show and hide elements based on a certain criteria.
You must use
filter:{color_name:by_colour}
instead ofIf you want to match with a single property of an object, then write that property instead of object, otherwise some other property will get match.
Search by color:
you can do an inner nest too.