Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何在ngx translate中使用货币管道?_Angular_Localization_Angular Pipe_Ngx Translate_Currency Pipe - Fatal编程技术网

Angular 如何在ngx translate中使用货币管道?

Angular 如何在ngx translate中使用货币管道?,angular,localization,angular-pipe,ngx-translate,currency-pipe,Angular,Localization,Angular Pipe,Ngx Translate,Currency Pipe,我正在使用ngx translate将我的角度应用程序内部化。我添加了一个下拉列表,有3种语言(fr、de和en)。在语言切换时,我想更改货币符号。我还添加了一个自定义管道,但它不起作用 table.component.html <p>{{'company' | translate}}</p> - this value is changing <p>{{payment.amount | mycurrency}}</p> - this valu

我正在使用ngx translate将我的角度应用程序内部化。我添加了一个下拉列表,有3种语言(fr、de和en)。在语言切换时,我想更改货币符号。我还添加了一个自定义管道,但它不起作用

table.component.html
 <p>{{'company' | translate}}</p>  - this value is changing
 <p>{{payment.amount | mycurrency}}</p> - this value is not changing



mycurrency.ts

import { Pipe, PipeTransform } from '@angular/core';
import { formatCurrency, getCurrencySymbol } from '@angular/common';
import { DEFAULT_LANGUAGE } from '@ngx-translate/core';
@Pipe({
    name: 'mycurrency',
})
export class MycurrencyPipe implements PipeTransform {
    code: any;
    constructor() {
        if (localStorage.getItem("language") == 'fr' || localStorage.getItem("language") == 'de') {
            this.code='EUR';
        }
        else {
            this.code ='USD';
        }
    }

    transform(
        value: number,
        currencyCode: string = this.code,
        display:
            | 'code'
            | 'symbol'
            | 'symbol-narrow'
            | string
            | boolean = 'symbol',
        digitsInfo: string = '3.2-2',
        locale: string = localStorage.getItem("language"),
    ): string | null {
        console.log("Ds");
        return formatCurrency(
            value,
            locale,
            getCurrencySymbol(currencyCode, 'wide'),
            currencyCode,
            digitsInfo,
        );
    }
}
'''


table.component.html
{{'company'| translate}

-此值正在更改 {{payment.amount | mycurrency}

-此值未更改 mycurrency.ts 从“@angular/core”导入{Pipe,PipeTransform}; 从“@angular/common”导入{formatCurrency,getcurrencycomsymbol}; 从'@ngx translate/core'导入{DEFAULT_LANGUAGE}; @烟斗({ 名称:“我的货币”, }) 导出类MycurrencyPipe实现PipeTransform{ 代码:任何; 构造函数(){ if(localStorage.getItem(“语言”)='fr'| | localStorage.getItem(“语言”)='de'){ 此代码为“=”欧元“; } 否则{ 此代码为“=”美元“; } } 转化( 值:number, currencyCode:string=this.code, 显示: |“代码” |“符号” |“符号窄” |串 |布尔值='symbol', DigitInfo:string='3.2-2', locale:string=localStorage.getItem(“语言”), ):字符串|空{ 控制台日志(“Ds”); 返回格式货币( 价值 场所 getCurrencySymbol(currencyCode,“宽”), 货币代码, digitsInfo, ); } } '''
您可以使用。查看此示例了解更多信息

您可以使用。查看此示例了解更多信息


您可以使用角度货币管道

table.component.html

<p>
    {{payment.amount | currency:currencyCode}}
</p>

{{payment.amount}货币:currencyCode}

currencyCode
可以是包含标准货币代码(“USD”、“EURO”、“INR”等)的变量,也可以从下拉列表中指定

检查下面的示例


您可以使用角度货币管道

table.component.html

<p>
    {{payment.amount | currency:currencyCode}}
</p>

{{payment.amount}货币:currencyCode}

currencyCode
可以是包含标准货币代码(“USD”、“EURO”、“INR”等)的变量,也可以从下拉列表中指定

检查下面的示例


好的。但当语言切换发生时,currencyCode值不会改变。当我将语言更改为{{'company'| translate}}以上时,公司值会更改,但货币不会更改。您可以共享您的语言开关下拉列表吗?好的。但当语言切换发生时,currencyCode值不会改变。当我将语言更改为{{'company'| translate}}以上时,公司价值会更改,但货币不会更改。您可以共享您的语言开关下拉列表吗?