【问题标题】:Use Angular Basic pipes within components在组件中使用 Angular Basic 管道
【发布时间】:2019-07-04 00:11:53
【问题描述】:

我试图在我的 Ionic 项目中的一个组件中使用 Angular 现成的管道(即日期、大写),但它给出了一个错误。

我在 src/app 文件夹中有一个组件文件夹。每个组件都在各自的文件夹中,其中包含 scss、html 和 ts 文件。

<div class="day">
  {{ day | date }}
</div>
<div class="month">
  {{ month | uppercase }}
</div>

我必须在某处导入 DateModule 吗?

【问题讨论】:

标签: angular ionic-framework


【解决方案1】:

没有任何名为 DateModule 的模块。

date pipe 是 CommonModule 的一部分(参见 @angular/common 包)。

CommonModule 导出由 BrowserModule 重新导出,它自动包含在根 AppModule 中(也在 Ionic 项目中)。

【讨论】:

    【解决方案2】:

    你可以从下面的链接看到管道:https://angular.io/guide/pipes

    下面是管道名称和用例列表。

    DatePipe:根据区域设置规则格式化日期值。

    UpperCasePipe:将文本全部转换为大写。

    LowerCasePipe:将文本全部转换为小写。

    CurrencyPipe:将数字转换为货币字符串,根据区域设置规则格式化。

    DecimalPipe:将数字转换为带小数点的字符串,根据区域设置规则格式化。

    PercentPipe:将数字转换为百分比字符串,根据区域设置规则格式化。

    【讨论】:

      猜你喜欢
      • 2016-05-10
      • 2016-08-17
      • 1970-01-01
      • 2020-10-29
      • 2016-12-05
      • 2017-03-13
      • 2019-02-19
      • 2022-11-07
      相关资源
      最近更新 更多