【问题标题】:Angular use currency and number pipes togetherAngular 一起使用货币和数字管道
【发布时间】:2021-09-16 13:01:34
【问题描述】:

使用角度 我的组件中有这个

export class AppComponent {
  currency = 'EUR';
  amount = 312.562;

我想在我的模板中以这种格式显示我的金额和我的货币

312.562 -> €000,000,312.562

我已经试过了:

{{ amount | number: '9.2' | currency: this.currency }}

但我有这个错误

Error: InvalidPipeArgument: '000,000,312.562 is not a number' for pipe 'CurrencyPipe'

那么,我怎样才能在不将其视为有效数字的情况下添加货币符号呢?

建议?

【问题讨论】:

    标签: angular typescript angular-template angular-pipe


    【解决方案1】:

    从它的签名中可以看出,货币管道与一些进一步的参数一起工作:

    transform(
      value: number|string|null|undefined, currencyCode: string = this._defaultCurrencyCode,
      display: 'code'|'symbol'|'symbol-narrow'|string|boolean = 'symbol', digitsInfo?: string,
      locale?: string)
    

    因此您可以在模板中简单地使用以下内容:

    {{ amount | currency: this.currency:'symbol':'9.3' }}
    

    (我不确定你是真的想要 9.2 还是 9.3,但最初你说你想要这 000,000,312.562 欧元。所以应该是 9.3)

    【讨论】:

      猜你喜欢
      • 2018-07-18
      • 2017-01-16
      • 2017-10-09
      • 2021-11-10
      • 2016-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      相关资源
      最近更新 更多