【问题标题】:How to include DatePipe in HTML to print lastModifiedDate如何在 HTML 中包含 DatePipe 以打印 lastModifiedDate
【发布时间】:2017-12-31 13:40:55
【问题描述】:

我有 file-upload.component.ts 我在其中导入 DatePipe

import { DatePipe } from '@angular/common';

然后我

export class FileUploadComponent implements OnInit { datePipe = new DatePipe(); }

在 file-upload.component.html 中 我设置了

  <td>{{ file.lastModifiedDate | date }} </td> 

我的错误在哪里?

【问题讨论】:

  • 请更详细地描述您的问题。会发生什么?管道通常不能导入到组件中,而是在您希望它在declarations: [] 下使用的@NgModule 中。
  • 从 '@angular/common' 导入 { DatePipe }; @NgModule({ declarations: [CommonModule] }) 在 app.module.ts 中?
  • @MaKobi 现在我有错误compiler.es5.js:1690 Uncaught Error: Unexpected module 'CommonModule' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation.

标签: javascript angular file-upload pipe angular2-forms


【解决方案1】:

DatePipe 根本不需要导入。 它是内置的,可以开箱即用

【讨论】:

  • 为什么不起作用? ` {{ 文件.lastModifiedDate |日期}} `
猜你喜欢
  • 1970-01-01
  • 2023-04-04
  • 2011-02-27
  • 1970-01-01
  • 1970-01-01
  • 2020-08-12
  • 1970-01-01
  • 2019-05-19
  • 2010-10-05
相关资源
最近更新 更多