I have the following field in Firestore:
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?
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>
Just place a ?
after fechaInicio
like:
<p>{{ fechaInicio?.toDate() | date }}</p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With