I
I
Ivan Stroykin2016-12-12 15:38:40
Angular
Ivan Stroykin, 2016-12-12 15:38:40

How to display the symbol of any currency through currency?

Good day,
There is an output of information through *ngFor to a table where there are currencies. The output is the following:

<td>{{total.sum | currency: total.currency_code : true : '.2'}}</td>

total.currency_code = different currencies. but the symbol is displayed only for the dollar (USD) and the euro (EUR), and for the rest, for example, the ruble (RUB), just the word "RUB" is displayed.
I was looking for information, a lot of different additions. But for some reason it seems to me that the chip is built-in. Has anyone experienced this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Zuev, 2016-12-12
@StivinKing

In Angular2, the currency pipe ultimately executes this function
https://developer.mozilla.org/en/docs/Web/JavaScri...
For the pipe to return the Russian ruble symbol. he needs to substitute the correct ru-RU locale. It can be overridden globally, but since you use different quotes, you can make a custom pipe
. For example, this is how it can work ( Plunker ):

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

const map = {
  'RUB': 'ru-RU',
  'JPY': 'ja-JP'
}

@Pipe({name: 'localizedCurrency'})
export class LocalizedCurrencyPipe implements PipeTransform {
  transform(value: any, currencyCode: string = 'USD', 
          symbolDisplay: boolean = false, digits: string = null): string {
    return new CurrencyPipe(map[currencyCode]).transform(value, currencyCode, symbolDisplay, digits);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question