使用Angular 我在我的組件中這樣做了
export class AppComponent {
currency = 'EUR';
amount = 312.562;
我想在我的模板中以這種格式顯示我的金額和我的貨幣
。312.562 -> €000,000, 312.562
我試著這樣做了 :
{{ amount | number: '9.2' | currency: this.currency }}。
但是我遇到了這個錯誤
Error: InvalidPipeArgument。'000,000,312.562 is not a number' for pipe 'CurrencyPipe'。
那么,我怎樣才能只預設貨幣符號而不把它當作一個有效數字呢?
建議?
uj5u.com熱心網友回復:
貨幣管道與一些進一步的引數一起作業,你可以從它的簽名中看到:
span class="hljs-title function_">transform(
value: number|string|null|undefined, currencyCode: string = this. _defaultCurrencyCode,
display。'code'|'symbol'|'symbol-narrow'|string|boolean = 'symbol', digitsInfo? : string,
locale?: string)
因此,你可以簡單地在你的模板中使用以下內容:
{{ amount | currency: this.currency:'symbol':'9.3' }}.
(我不確定你是否真的想要9.2或9.3,但最初你說你想擁有這個€000,000,312.562。所以應該是9.3)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/307911.html
標籤:
