Angular2 date pipe does not work in IE 11 and edge 13/14

前端 未结 8 1334
闹比i
闹比i 2020-12-05 09:50

I\'m using Angular 2.0 final, and I have an incorrect format of dates when I add hours and minutes in the format string:

In the template of the component, I have:

8条回答
  •  离开以前
    2020-12-05 10:16

    Regarding the answer from @mark-hughes above, from the moment API documentation:

    date_expression | date[:format]

    expression is a date object or a number (milliseconds since UTC epoch) or an ISO string

    Reference

    So the value should be any type, and you can use moment().isValid() to check the value type

    @Pipe({name: 'datex'})
    export class DatexPipe implements PipeTransform {
        transform(value: any, format: string = ""): string {
           return moment(value).isValid()? moment(value).format(format) : value; 
        }
    }
    

提交回复
热议问题