Why is my custom filter predicate filter not working
<p>I have an use case wherein I have to filter an array based on selection from two dropdowns. Both the selections are from md-select (from Angular material) hence both the selection will be an array. Any record from the original array that matches any of the record from the selection arrays should be returned by filter.</p>

<p>I have returned the following logic, but I can't figure out why my data do not get filtered.</p>

<pre><code>$scope.filterTasks = function (t, i, array) {
  if ($scope.filter.tradeDir.length === 0 &amp;&amp; $scope.filter.cluster.length === 0) {
    return true;
  }
  else if ($scope.filter.tradeDir.length !== 0 &amp;&amp; $scope.filter.cluster.length === 0) {
    $scope.filter.tradeDir.forEach(function (td) {
      if ((t.Trade.code === td.trade.code) &amp;&amp; (t.Direction.code === td.direction.code)) {
        return true;
      }
    });
  } else if ($scope.filter.cluster.length !== 0 &amp;&amp; $scope.filter.tradeDir.length !== 0) {
    $scope.filter.tradeDir.forEach(function (td) {
      if ((t.Trade.code === td.trade.code) &amp;&amp; (t.Direction.code === td.direction.code)) {
        $scope.filter.cluster.forEach(function(c) {
          if (t.Cluster.code === c.code) {
            return true;
          }
        });
      }
    });
  }
  else {
    return false;
  }
}
</code></pre>

<p>Surprisingly, when I debug, I can see the control going till the return statement for each matched record. Still, the data does not get filtered. I am puzzled why?</p>

<p>Below is my html code for md-selects:</p>

<pre><code>&lt;div class="filter layout layout-sm-column task_top_filters"&gt;
  &lt;md-input-container ng-class="{'md-input-has-value': filter.tradeDir}" 
                      class="flex-sm-100 md_container_fr_task"&gt;
    &lt;label&gt;Trade/Direction&lt;/label&gt;
    &lt;md-select multiple ng-model="filter.tradeDir" 
                        md-on-close="closeTradeFilter(filter.tradeDir)"
                        ng-model-options="{trackBy: '$value.name'}"&gt;
      &lt;md-option ng-value="t" ng-repeat="t in tradeDirArray track by $index"&gt;
        {{t.name}}
      &lt;/md-option&gt;
    &lt;/md-select&gt;
  &lt;/md-input-container&gt;
  &lt;md-input-container  ng-disabled="filter.tradeDir.length === 0"
                       ng-class="{'md-input-has-value': filter.cluster}"
                       class="flex-sm-100 md_container_fr_task"&gt;
    &lt;label&gt;Cluster&lt;/label&gt;
    &lt;md-select multiple ng-model="filter.cluster" 
                        ng-model-options="{trackBy: '$value.code'}"&gt;
      &lt;md-option ng-value="t" ng-repeat="t in filterClusters track by $index"&gt;
        {{t.code}}
      &lt;/md-option&gt;
    &lt;/md-select&gt;
  &lt;/md-input-container&gt;
&lt;/div&gt;
</code></pre>

<p>and here is how I am calling it:</p>

<pre><code>&lt;li ng-repeat="t in dataList| filter: filterTasks track by t.id" class="li_row"&gt;
</code></pre>

<p>Is there something wrong with the filter? Any help will be appreciated.</p>