Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error toDate() InvalidPipeArgument: 'Unable to convert Timestamp.. Firebase

I have the following field in Firestore: enter image description here

When I try to get it in my application, for example:

<p>{{ fechaInicio | date }}</p> Get the following error:

ERROR Error: InvalidPipeArgument: 'Unable to convert "Timestamp(seconds=1553230800, nanoseconds=0)" into a date' for pipe 'DatePipe'

then I saw that adding toDate() supposedly fixes the problem:

<p>{{ fechaInicio.toDate() | date }}</p>

This shows the date correctly, however I get the following error:

ERROR TypeError: Cannot read property 'toDate' of undefined

How can I solve that?

like image 337
Paco Zevallos Avatar asked Mar 13 '19 03:03

Paco Zevallos


Video Answer


2 Answers

It seems like the variable 'fechaInicio' loads asynchronously. If so, 'fechaInicio' remains undefined till it get updated. Therefore, what you can do is hiding the html paragraph until the data get loaded to the variable.

Try the following modification.

<p *ngIf="fechaInicio">{{ fechaInicio.toDate() | date }}</p>
like image 146
Dulanjaya Tennekoon Avatar answered Sep 25 '22 15:09

Dulanjaya Tennekoon


Just place a ? after fechaInicio like:

<p>{{ fechaInicio?.toDate() | date }}</p>
like image 32
Bruno Andrade Avatar answered Sep 22 '22 15:09

Bruno Andrade