我使用ngx-translate来实现我的angular应用程序的内部化。我添加了一个包含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,
);
}
}
'''发布于 2020-04-13 14:37:35
您可以使用getCurrencySymbol。有关更多信息,请查看此示例。
https://stackblitz.com/edit/angular-currency-symbol-pipe-9pvmdc
发布于 2020-04-13 14:49:01
您可以使用角度货币管道。
table.component.html
<p>
{{payment.amount | currency:currencyCode}}
</p>currencyCode可以是包含标准货币代码(“美元”、“欧元”、“印度卢比”等)的变量,也可以从下拉列表中赋值。
检查下面的示例
https://stackoverflow.com/questions/61182459
复制相似问题