Skip to content

Instantly share code, notes, and snippets.

@AndrewAllison
Created October 28, 2016 09:43
Show Gist options
  • Save AndrewAllison/4d33ebdbcc854a837b674ca7c61b8c2c to your computer and use it in GitHub Desktop.
Save AndrewAllison/4d33ebdbcc854a837b674ca7c61b8c2c to your computer and use it in GitHub Desktop.
Common Pipes for angular 2 in typescript
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'jsonDate'
})
export class JsonDatePipe implements PipeTransform {
transform(value: any, args?: any): any {
if (value) {
return new Date(parseInt(value.substr(6)));
} else {
return value;
}
}
}
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'search'
})
export class SearchPipe implements PipeTransform {
transform(value: any, args?: any): any {
let filter: Array<any> = [];
if ((value instanceof Array && value.length > 0) && (args !== undefined && args !== '')) {
value.forEach(function (item) {
let searchResult = item['Name'].toLowerCase().search(args.toLowerCase());
if (searchResult >= 0) {
filter.push(item);
}
});
} else {
filter = value;
}
return filter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment