How to pass a JSON object returned from service in HTML as a parameter to pipe in angular

310 Views Asked by At

I have the below code in my HTML. currencyCustomFormat is a custom Pipe. Now in this custom pipe file, i would like to access the E_CURRENCY value ( value could be AUD or NZD or any other currency fetched from service) . How can i access this.

@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>

0

There are 0 best solutions below