0

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.

guyaloni
  • 4,972
  • 5
  • 52
  • 92

1 Answers1

4

You are using the built in Angular2 date pipe, date instead of your momentPipe, | moment:

However, you should still be able to do this with date

{{startDate | date: 'EEE'}}
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • 1
    If you are not using `momentPipe` for anything else, remove the library and use the native Angular2 date pipe as suggested here! – cnorthfield Mar 20 '17 at 23:08