Mistalis Mistalis - 1 year ago 80
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download