gpt4 book ai didi

angular - 管道日期 Angular "Unable to convert "时间戳”

转载 作者:太空狗 更新时间:2023-10-29 17:41:35 26 4
gpt4 key购买 nike

我正在尝试使用 Angular 管道,具体如下:{{fechaCreacion | date: 'medium'}} 并且出现以下错误:Unable to convert Timestamp (seconds = 1528157765, nanoseconds = 878000000)"into a date 'for pipe' DatePipe'

这是我在 Firestore 中的注册: enter image description here

当我刚离开 {{ fechaCreacion }} 时,它会显示以下内容:

enter image description here

我该如何解决?

我正在使用:

Angular 6

"angularfire2": "^5.0.0-rc.10"

"firebase": "^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 时间戳转换为 Javascript 日期对象,例如:

{{ creationDate.toDate() |日期:'中'}}

关于angular - 管道日期 Angular "Unable to convert "时间戳”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50956255/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com