获取货币符号角度2 [英] Get currency symbol angular 2

查看:132
本文介绍了获取货币符号角度2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用角度2和货币管道构建应用程序,但我找不到根据ISO值获取货币符号的方法,没有任何数字。我的意思是我只想要符号而不设置要格式化的数字。

I'm building an application using angular 2 and currency pipe, but I can't find a way to get the currency symbol according to the ISO value without any number. What I mean is that I just want the symbol without setting a number to be formatted.

正常情况 $ 3.00
我只想要 $符号,而不是数字

Normal situation $3.00 I want only the $symbol, not the number

推荐答案

因为我只想要货币的符号,所以我最终用一个常数来扩展货币管道,只返回符号。有一个恒定数字感觉有点黑客,但由于我不想创建新的货币地图而且我无法提供数字,我认为这是最简单的方法。

As I ONLY wanted the symbol for the currency, I ended up extending currency pipe with a constant number and return only the symbol. It feels sort of a "hack" to have a constant number, but as i don't want to create new currency maps and I'm not able to provide a number, i think is the easiest way.

这是我做的:

import { Pipe, PipeTransform } from '@angular/core';
import {CurrencyPipe} from "@angular/common";

@Pipe({name: 'currencySymbol'})
export class CurrencySymbolPipe extends CurrencyPipe implements 
PipeTransform {
    transform(value: string): any {
    let currencyValue = super.transform(0, value,true, "1.0-2");
    return currencyValue.replace(/[0-9]/g, '');
    }
}

现在我可以将它用作:

{{'EUR' | CurrencySymbolPipe}} and get '€'

感谢您的帮助和想法!

这篇关于获取货币符号角度2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆