Answer the question
In order to leave comments, you need to log in
Error TS2345 when using moment js how to fix?
there is such pipe
import { Pipe, PipeTransform } from '@angular/core'
import * as moment from 'moment'
@Pipe({
name: 'moment'
})
export class MomentPipe implements PipeTransform {
transform(momentObj: moment.Moment, format: string ="MMMM YYYY"): string {
return momentObj.format(format)
}
}
<p>
<i class="material-icons" (click)="month(-1)">arrow_left</i>
<span>
{{date.date | async | moment}}
</span>
<i class="material-icons" (click)="month(1)">arrow_right</i>
</p>
Answer the question
In order to leave comments, you need to log in
Adding null through the Union type helped me
export class MomentPipe implements PipeTransform {
transform(m: moment.Moment | null , format: string = 'MMMM YYYY'): string {
return m!.format(format)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question