Bolboa Bolboa - 3 months ago 7
AngularJS Question

How to merge two filters (AND operation)

I have two menus with options...

<div class="date_menu" ng-repeat="singledate in dates">
<p>
{{singledate}}
<input type="radio" name="filterDateChosen" ng-model="$parent.dateFilter" ng-value="singledate">
</p>
</div>


<div class="date_menu" ng-repeat="singledate in dates">
<p>
{{singledate}}
<input type="radio" name="filterDateChosen2" ng-model="$parent.dateFilter2" ng-value="singledate">
</p>
</div>


These filters work on their own, so if I use only one of them in this way, it works...

<div class="form-container" ng-repeat="formblock in forms | filter:dateFilter">


...This will filter by a chosen date value.

But what I want is for the user to choose and option from the first menu, and choose and option from the second menu, so if the user picks from menu 1
feb 26
and in the second menu they choose
march 1
, I want the to show all formblock with either dates
march 1
or
feb 26
.

I tried the following but it does not provide the proper results...

<div class="form-container" ng-repeat="formblock in forms | filter:dateFilter | filter:dateFilter2">


How can I filter using both filters inclusively?

Answer

Use this Expression {{ expression | filter1 | filter2 }}

<div class="form-container" ng-repeat="formblock in forms | filter:{  datefilter | datefilter2 }">
Comments