How to filter multiple values (OR operation) in angularJS

前端 未结 20 1267
清酒与你
清酒与你 2020-11-22 10:01

I want to use the filter in angular and want to filter for multiple values, if it has either one of the values then it should be displayed.

I have for

20条回答
  •  再見小時候
    2020-11-22 10:15

    Creating a custom filter might be overkill here, you can just pass in a custom comparator, if you have the multiples values like:

    $scope.selectedGenres = "Action, Drama"; 
    
    $scope.containsComparator = function(expected, actual){  
      return actual.indexOf(expected) > -1;
    };
    

    then in the filter:

    filter:{name:selectedGenres}:containsComparator
    

提交回复
热议问题