AngularJS filter on multiple values of one field


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

$scope.products = [

With the filter ng-repeat="item in products | filter:{type:'fruit'}". I can get all of the fruits. But what if I want to get all of the fruits and vegetables. I tried

ng-repeat="item in products | filter:{type:['fruit','vegetable']}"

But that didn't work. I figure there should be a simple solution to this, but I couldn't find it.

JSFiddle Example

Problem courtesy of: Danny


Use a filter function instead:

$scope.fruitOrVeg = function(product){
    return product.type == 'fruit' || product.type == 'vegetable';

<li ng-repeat="item in products | filter:fruitOrVeg">{{}}</li>


Solution courtesy of: Gruff Bunny


<!-- you can also use a function this simpler way-->

<div ng-repeat="product in products | filter: myFilter">

$scope.myFilter = function (item) { 
   return product.type == 'fruit' || product.type == 'vegetable';
Discussion courtesy of: Rick Il Grande

This recipe can be found in it's original form on Stack Over Flow.