Angular 2 - DatePipe issue

1,287 views
Skip to first unread message

levyuk

unread,
Jan 21, 2016, 5:13:13 AM1/21/16
to AngularJS
Anyone know why when I try to format a date with the date pipe I get the following error?

Invalid argument '2016-01-19T10:10:49.892688Z' for pipe 'DatePipe' in [ {{app.LastUpdated|date}}

Thanks
Jon

Günter Zöchbauer

unread,
Jan 21, 2016, 7:48:02 AM1/21/16
to AngularJS
You get this error if the value doesn't pass this check


supports(obj: any): boolean { return isDate(obj) || isNumber(obj); }


export function isDate(obj): boolean { return obj instanceof Date && !isNaN(obj.valueOf());}

so, the value has to be either of type `Date` or `number`

This might work (not tried)

{{new Date(app.LastUpdated)|date}}

levyuk

unread,
Jan 21, 2016, 7:51:59 AM1/21/16
to AngularJS
It looks like it is the format of the date which is causing the problem. If I do

new Date(myDate)|date 

then it works fine. 

Thanks
Jon

Günter Zöchbauer

unread,
Jan 21, 2016, 8:16:43 AM1/21/16
to AngularJS

Jonathan Levy

unread,
Jan 21, 2016, 8:18:00 AM1/21/16
to ang...@googlegroups.com
I've just commented on it :)

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/8aivgqbvrbw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages