Mistalis Mistalis - 8 months ago 41
AngularJS Question

Filter data according to several attribute values

I would like to filter

array in a
with some buttons:

  • The first one shows all the messages.

  • The second shows messages of type A and B.

  • The last one show messages of type C only.

My problem is for the second button, because it has to filter on 2 differents types (A and B). I tried to filter on
['B', 'C']
, but it seems that
does not accept an array of values.

Here is a piece of code that will allow you to better understand my issue:

<a ng-click="typeMsg = undefined">All</a>
<a ng-click="typeMsg = ['A', 'B']">Type A and B</a>
<a ng-click="typeMsg = 'C'">Type C</a>

<div ng-repeat="m in messages | filter: {type: typeMsg}">

Is there a way to do this 100% in HTML, without writing a custom filter for this case?


If you only have ['A', 'B', 'C'] as possible values you can do '!C' to only show 'A' and 'B'. Otherwise you have to write a custom filter method.