/ng2-timeago

angular2 timeago component

Primary LanguageJavaScriptMIT LicenseMIT

ng2-timeago

a small angular2 component for displaying how long ago from now.

installation

use npm:

npm install ng2-timeago --save

property

time (required:Date || Number)

The time you want to be transformed.

live (optional: Boolean)

default true. set to 'false' if you don't want to live update.

interval (optional: Number)

Live update interval. Default 60*1000(1 minute).

maxPerid (optional: Number)

If time longer than maxPerid, it will show a special date format you setted via afterMaxDateFormat. Defalut 365 * 24 * 60 * 60 * 1000(1 year).

afterMaxDateFormat (optional: String)

Default 'medium', for more supported date format, see datePipe in angular2 doc.

suffix (optional: String)

default 'ago', time ago suffix, you can use other words, eg: 'from now'.

how to use

import {TimeAgo} from 'ng2-timeago/timeago'

@Component({
    selector: 'foo',
    template: `<time-ago [time]="time" [maxPeriod]="30*24*60*60"> `,
    directives: [TimeAgo]
})
class Foo {
    time: Date = new Date(Date.now() - 5 * 24 * 60 * 60 * 1000)
}

Todo

Complete the test case.