Skip to content

Instantly share code, notes, and snippets.

@mhartington
Created April 15, 2016 18:37
Show Gist options
  • Save mhartington/137d23f67ddebc4850d21798fd16d1ba to your computer and use it in GitHub Desktop.
Save mhartington/137d23f67ddebc4850d21798fd16d1ba to your computer and use it in GitHub Desktop.
import {Injectable, Pipe} from 'angular2/core';
@Injectable()
@Pipe({ name: 'filter' })
export class FilterArrayPipe {
transform(value, args) {
if (!args[0]) {
return value;
} else if (value) {
return value.filter(item => {
for (let key in item) {
if ((typeof item[key] === 'string' || item[key] instanceof String) &&
(item[key].indexOf(args[0]) !== -1)) {
return true;
}
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment