1

我的 HTML 中有以下代码。currencyCustomFormat 是一个自定义管道。现在在这个自定义管道文件中,我想访问 E_CURRENCY 值(值可以是 AUD 或 NZD 或从服务中获取的任何其他货币)。我怎样才能访问这个。

@Pipe({
  name: 'currency'
})
export class CurrencyPipe implements PipeTransform {
  translateService
  @select(user) currentUser$
  constructor() {}
  transform(value, country): string {
    if (!value) {
      return ''
    } else {
      if (!country) {
        country = 'NZD'
      }
      const symbol = symbols[country] //value of symbol is $
      if (symbol) {
        this.currentUser$.first().subscribe(v => {
          this.translateService.use(v.E_LOCALE);

          const decimalSepValue = this.translateService.instant('CURRENCYFORMATS.' + currencyCode + '.DECIMALSEPARATOR');
          const thousandSepValue = this.translateService.instant('CURRENCYFORMATS.' + currencyCode + '.THOUSANDSEPARATOR');
          const currencyDecValue = this.translateService.instant('CURRENCYFORMATS.' + currencyCode + '.CURRENCYDECIMALS'); // **i need to pass the value of E_CURRENCY to currencyCode variable**
          return accounting.formatMoney(value, {
            symbol,
            format: '%s %v',
            precision: currencyDecValue,
            thousand: thousandSepValue,
            decimal: decimalSepValue
          })
        })
      };
      return accounting.formatMoney(value, {
        symbol: country,
        format: '%v %s'
      });
    }
  }
}
<div label="ORDER_DETAILS.TOTAL_PRICE" [value]="order.details.E_NET_PRICE | currencyCustomFormat: order.details.E_CURRENCY"></div>

4

0 回答 0