我正在尝试使用有角度的管道,特别是以下内容:{{fechaCreacion | date: 'medium'}},并且出现以下错误:Unable to convert Timestamp (seconds = 1528157765, nanoseconds = 878000000)" into a date 'for pipe' DatePipe'
I'm trying to use a pipe in angular, specifically the following: {{fechaCreacion | date: 'medium'}} and I get the following error: Unable to convert Timestamp (seconds = 1528157765, nanoseconds = 878000000)" into a date 'for pipe' DatePipe'
这是我在Firestore中的注册:
This is my registration in Firestore:
当我刚刚离开{{ fechaCreacion }}时,它向我显示以下内容:
When I just leave {{ fechaCreacion }} it shows me the following:
我该如何解决?
我正在使用:
角度6
"angularfire2":"^ 5.0.0-rc.10"
"angularfire2": "^5.0.0-rc.10"
"firebase":"^ 5.0.4",
"firebase": "^5.0.4",
component.ts
component.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 }); }component.html
component.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>service.ts
service.ts
getAvisoObject(id: string) { this.avisoObject = this.afs.doc('avisos/' + id); return this.avisoObject; }推荐答案
在Firestore中处理时间戳记类型数据(即显示的文档中的fechaCreacion字段)时,Firestore客户端库将为您提供时间戳类型对象,以响应查询.您需要使用此时间戳来设置日期格式,以便在浏览器中显示.
When dealing with timestamp type data in Firestore (that's your fechaCreacion field in the document shown), the Firestore client libraries will give you a Timestamp type object in response to queries. You need to use this Timestamp to format a date for display in the browser.
时间戳表示具有纳秒精度的时间,其中涉及两个整数,您将在屏幕上看到它们.如果要使用JavaScript Date对象,则可以使用 toDate( )在该时间戳上进行转换,或将其转换为屏幕上的内容.
Timestamp represents times with nanosecond precision, which involves two integers, which you are seeing on screen. If you want a JavaScript Date object instead, you could use the toDate() method on that Timestamp to convert it, or whatever it is you need to render that on screen.
更多推荐
管道日期角度“无法转换"时间戳"
发布评论