AngularJS scope Example

HTML

<div ng-app="myapp" >
   <div ng-controller="ctrl1"> 
       <div ng-repeat="hash in hashes | filter: {type:'foo'}">
           {{hash.a}}
       </div>
       second list:
          <div ng-repeat="hash in hashes | inArray: types">
           {{hash.a}}
       </div>


</div>

JavaScript

var myapp = angular.module("myapp", []);


myapp.controller("ctrl1", function ($scope) {
    
  $scope.hashes = [
  {
      "type": "foo"
      , "a": "1"
  }
  , {
      "type": "foo"
   , "a": "2"
  }
  , {
      "type": "bar"
    , "a": "3"
  }
  , {
      "type": "quz"
    , "a": "4"
  }
      , {
      "type": "quz"
    , "a": "5"
  }
];
    
    $scope.types = ['foo','quz'];
    
    $scope.filterArray = function(hash) {
        return ($scope.types.indexOf(hash.type) !== -1);
    };

});

myapp.filter('inArray', function() {
    return function inArray( haystack , needle ) {
        var result = [];
        var item,i;
        for (i=0; i< haystack.length;i++) {
            item = haystack[i];
            if (needle.indexOf(item.type) !== -1)
              result.push(item);
        };
        return (result);
    };
});