Created
February 7, 2018 15:46
-
-
Save pimatco/ca5f9c4dc89f84679d72390e0715aa04 to your computer and use it in GitHub Desktop.
Pipe with timeago for Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Pipe, PipeTransform } from '@angular/core'; | |
import * as moment from 'moment'; | |
//insert your locale | |
moment.locale('pt-br'); | |
@Pipe({ | |
name: 'timeago', | |
}) | |
export class TimeagoPipe implements PipeTransform { | |
transform(value) { | |
//formats the value to make sure its moment | |
let formatted = moment().format(value); | |
//convert to timeago | |
let timeAgo = moment(value).fromNow(); | |
return timeAgo; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment