AngularJS filter on multiple values of one field

前端 未结 1 389
温柔的废话
温柔的废话 2021-01-04 08:51

I need to be able to filter on two different values of one field of an object. Take the following example.

$scope.products = [
    {name:\"Apple\",type:\"fru         


        
相关标签:
1条回答
  • 2021-01-04 09:27

    Use a filter function instead:

    $scope.fruitOrVeg = function(product){
        return product.type == 'fruit' || product.type == 'vegetable';
    };
    
    <li ng-repeat="item in products | filter:fruitOrVeg">{{item.name}}</li>
    

    Fiddle

    0 讨论(0)
提交回复
热议问题