Angular InArray Filter

Filter results that are contained inside an array

Download .zip Download .tar.gz View on GitHub

Welcome to Angular-InArray-Filter repository.

Clone this repository:

$ git clone https://github.com/cyberdelphos/angular-inarray-filter.git

If you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.

Description

In this repository you can find a filter for AngularJS to filter results that are contained inside an array.

Installation

To use this filter you have to:

  1. Download the zip located at this repo's '/dist' directory and copy its contents to your project's libraries directory (usually '/lib')
  2. Inject the module 'filters-inArrayFilter' to your Angular App definition (usually in your 'app.js' file)
    angular.module('MyApp', [ 'MyApp.controllers', ... , 'filters-inArrayFilter' ])
  3. Add this script to your html code:
    <script src="lib/angular-inarray-filter/angular-inarray-filter.js">

Usage

  1. Use angular notation to filter your repeaters:
  • Filter by specific elements of the array:
    <span ng-repeat='element in array | inArray:filterArray:"id"'> {{element.id}} </span>
    where inArray is the filter, filterArray (the first argument of this filter) is your array to match against, and "id" (second argument) is the element of the list you want to match against the array.

  • Filter a plain array:
    <span ng-repeat='element in plainArray | inArray:filterArray'> {{element}} </span>
    where inArray is the filter, filterArray (the first argument of this filter) is your array to match against your plain array.

Samples

Take a look at this page to see a live sample using these filters.

First you'll find a sample filtering by specific elements of array. Second, you'll find a sample filtering plain arrays.

Authors and Contributors

This directive is created by A. Carrasco (@cyberdelphos) based on a stackoverflow answer by @InviS and is released under the MIT License.