【问题标题】:Error toDate() InvalidPipeArgument: 'Unable to convert Timestamp.. Firebase错误 toDate() InvalidPipeArgument: '无法转换时间戳.. Firebase
【发布时间】:2019-08-03 15:42:26
【问题描述】:

我在 Firestore 中有以下字段:

当我尝试在我的应用程序中获取它时,例如:

<p>{{ fechaInicio | date }}</p> 得到以下错误:

错误错误:InvalidPipeArgument:'无法转换 将“时间戳(秒=1553230800,纳秒=0)”转换为管道的日期 '日期管道'

然后我看到添加 toDate() 据说可以解决问题:

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

这显示日期正确,但我收到以下错误:

错误类型错误:无法读取未定义的属性“toDate”

我该如何解决?

【问题讨论】:

  • 变量fechaInicio是异步加载的吗?
  • 是的,异步

标签: angular firebase google-cloud-firestore


【解决方案1】:

变量“fechaInicio”似乎是异步加载的。如果是这样,“fechaInicio”在更新之前保持未定义。因此,您可以做的是隐藏 html 段落,直到数据加载到变量中。

尝试以下修改。

<p *ngIf="fechaInicio">{{ fechaInicio.toDate() | date }}</p>

【讨论】:

  • 谢谢,这行得通!。解释很有趣。
【解决方案2】:

只需在fechaInicio 之后放置一个? 即可:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-16
    • 2021-10-16
    • 1970-01-01
    • 2021-10-17
    • 2017-02-05
    • 2015-11-24
    • 2017-06-26
    • 2017-11-02
    相关资源
    最近更新 更多