I implemented the following custom pipe in my angular 2 app:
import { Injectable, Pipe } from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'momentPipe'
})
@Injectable()
export class MomentPipe {
transform(value: Date|moment.Moment, ...args: any[]): any {
let [format] = args;
return moment(value).format(format);
}
}
It works well with 'standard' formats:
{{startDate | date : 'dd/MM/yyyy' }}
But when I try to print the day name:
{{startDate | date : 'ddd' }}
I get on the screen simply ddd
. Just to be sure, in the ts
file I do:
console.log(moment(this.startDate).format('ddd'));
and I get Sat
for example.
I guess it has to do with compilation, but couldn't find neither good explanation nor a solution for it.