无法在Angular上显示日期管道

时间:2018-06-03 14:42:04

标签: javascript angular firebase

我想显示一个带有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}} &bull; 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}} &bull; 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>

当我将鼠标悬停在已发布的:新日期()中的日期时, 它有这样的信息:

  

const日期:DateConstructor

     

new()=&gt;日期(+4超载)

如果您知道,有什么问题,请告诉我要更改什么,以使日期管道显示在我的帖子上。

1 个答案:

答案 0 :(得分:0)

你必须在帖子列表html中写这个并发布详细信息html:

&bull; on {{post.published.toDate() | date: 'fullDate'}}