angular - 管道日期角度“无法转换”时间戳“
问题描述
我正在尝试使用有角度的管道,特别是以下内容:{{fechaCreacion | date: 'medium'}}
并且我收到以下错误:Unable to convert Timestamp (seconds = 1528157765, nanoseconds = 878000000)" into a date 'for pipe' DatePipe'
当我离开{{ fechaCreacion }}
时,它向我显示以下内容:
我该如何解决?
我在用着:
角 6
“angularfire2”:“^5.0.0-rc.10”
“火力基地”:“^5.0.4”,
组件.ts
aviso: any = {};
id;
titulo;
descripcion;
fechaCreacion;
categoria;
constructor( private fs: FirebaseService, private activatedRoute: ActivatedRoute) { }
ngOnInit() {
this.id = this.activatedRoute.snapshot.params['id'];
this.fs.getAvisoObject(this.id).valueChanges().forEach(aviso => {
this.titulo= aviso.titulo,
this.descripcion = aviso.descripcion,
this.fechaCreacion = aviso.fechaCreacion,
this.categoria = aviso.categoria
});
}
组件.html
<mat-card class="px-3 px-md-5 py-3 py-md-4 rounded">
<div class="row no-gutters small pb-2 mb-3 d-flex justify-content-between border-bottom text-muted">
<div>
<span>{{ categoria }}</span>
</div>
<div>
<span>{{ fechaCreacion | date : 'medium' }}</span>
</div>
</div>
<h2 class="font-weight-bold">{{ titulo }}</h2>
<h5 class="font-weight-light">{{ descripcion }}</h5>
</mat-card>
服务.ts
getAvisoObject(id: string) {
this.avisoObject = this.afs.doc('avisos/' + id);
return this.avisoObject;
}
解决方案
您必须在管道之前调用toDate()
将 Firebase Timestamp 转换为 Javascript Date 对象,例如:
{{ creationDate.toDate() | date: 'medium' }}
推荐阅读
- python - 使用新观察到的数据更新 PyMC3 上的模型
- c# - 权限处理的设计建议
- javascript - 使用 vanilia js 和 css 的动画移动动画
- eclipse - 创建分支后从 master 获取更改
- javascript - 使用 ImageMapster 更改选定区域的填充颜色
- google-analytics - 我如何知道用户在确定的一天时间内来自哪里?(谷歌分析)
- c++ - cmake 与包含和库的路径有关的问题
- python - 当约束兼容时,SciPy SLSQP 声称约束不兼容
- django - 关闭 Django 已安装包中的命令
- javascript - 从 SVG 中的 shadowRoot 元素向上遍历树