Skip to content

Instantly share code, notes, and snippets.

@gchokeen
Created March 29, 2017 18:38
Embed
What would you like to do?
Angular 2 custom pipe for age
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'age'
})
export class AgePipe implements PipeTransform {
transform(value: Date|moment.Moment, args: string[]): any {
if (!value) return value;
return moment().diff(value, 'years')+" Years";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment