javascript - 无法在 Angular 上显示日期管道
问题描述
我想显示一个带有 angularjs 和 firebase 的日期管道,以显示我何时创建帖子。当有帖子列表并且我看到帖子的详细信息但在我测试它时没有显示任何内容时。
这是我的创建帖子功能:
createPost() {
const data = {
author: this.auth.authState.displayName || this.auth.authState.email,
authorId: this.auth.currentUserId,
content: this.content,
image: this.image,
published: new Date(),
title: this.title
};
接下来是帖子列表html:
<section>
<mat-card *ngFor="let post of posts | async">
<mat-card-content routerLink="{{post.id}}">
<img src="{{post.image}}" alt="{{post.title}}">
<h2>{{post.title}}</h2>
<p><small>Posted by {{post.author}} • on {{post.published * 1000 | date: 'fullDate'}}</small></p>
</mat-card-content>
<mat-card-actions align="end" *ngIf="auth.currentUserId === post.authorId">
<button mat-icon-button (click)="delete(post.id)">
<mat-icon>delete</mat-icon>
</button>
</mat-card-actions>
</mat-card>
</section>
并发布详细信息html:
<div [hidden]="editing">
<mat-card>
<img src="{{post.image}}" alt="{{post.title}}">
<p>
<small>Posted by {{post.author}} • on {{post.published * 1000 | date: 'fullDate'}}</small>
</p>
<mat-card-content>
<h2>{{post.title}}</h2>
<p>{{post.content}}</p>
</mat-card-content>
<mat-card-actions align="end" *ngIf="auth.currentUserId === post.authorId">
<button mat-icon-button (click)="editing=true">
<mat-icon>edit</mat-icon>
</button>
<button mat-icon-button (click)="delete()">
<mat-icon>delete</mat-icon>
</button>
</mat-card-actions>
</mat-card>
</div>
此外,当我将鼠标悬停在已发布的日期上时:new Date(), 它有以下消息:
常量日期:DateConstructor
new () => Date(+4 重载)
如果您知道这有什么问题,请告诉我要更改哪些内容以使日期管道显示在我的帖子上。
解决方案
您必须在 post list html 和 post detail html 中编写:
• on {{post.published.toDate() | date: 'fullDate'}}
推荐阅读
- python - Python中的编码结构
- go - 如何使变量线程安全
- jenkins - UnsupportedOperationException:必须使用接口 java.util.List 的实现指定 $class
- python - 使用 BeautifulSoup 4 和递归捕获 HTML 嵌套标签的结构
- c++ - 矢量大小()被 NetBeans 标记为错误:无法解析标识符
- c - C 中的预期表达式
- javascript - MYSQL - PHP - 使用从提交按钮传递的变量更新数据库中的值
- javascript - 从 dataTable 行访问嵌套的对象数组
- date - 如果 golang 中的条件出错
- xaml - 图像未显示在 MVVM XAML Xamarin 表单上