-import { DatePipe } from '@angular/common'
-import { Component, Input, OnChanges, OnInit } from '@angular/core'
+import { Component, Input, OnChanges } from '@angular/core'
import { FromNowPipe } from '../angular/from-now.pipe'
@Component({
templateUrl: './date-toggle.component.html',
styleUrls: [ './date-toggle.component.scss' ]
})
-export class DateToggleComponent implements OnInit, OnChanges {
+export class DateToggleComponent implements OnChanges {
@Input() date: Date
@Input() toggled = false
dateRelative: string
dateAbsolute: string
- constructor (
- private datePipe: DatePipe,
- private fromNowPipe: FromNowPipe
- ) { }
-
- ngOnInit () {
- this.updateDates()
- }
+ constructor (private fromNowPipe: FromNowPipe) { }
ngOnChanges () {
this.updateDates()
}
getTitle () {
- return this.toggled ? this.dateRelative : this.dateAbsolute
+ return this.toggled
+ ? this.dateRelative
+ : this.dateAbsolute
}
getContent () {
- return this.toggled ? this.dateAbsolute : this.dateRelative
+ return this.toggled
+ ? this.dateAbsolute
+ : this.dateRelative
}
private updateDates () {
this.dateRelative = this.fromNowPipe.transform(this.date)
- this.dateAbsolute = this.datePipe.transform(this.date, 'long')
+ this.dateAbsolute = this.date.toLocaleDateString()
}
}