Shane
Shane

Reputation: 5687

Invalid argument '$0' for pipe 'CurrencyPipe'

I am getting from backend as $0, i want to display it as $0.00 in my UI.

<span [innerHTML]="session.balance | currency :'USD': true:'1.2-2'"></span>

Why is it failing when my backend gives me the balance as $0 and does not fail when it gives me just a number 0. This was working fine in Angular 1 while using the currency filter.

Removing the currency filter also removed the two decimal places which i used to get. I am not sure whether i should go with number : '1.2-2'

Upvotes: 3

Views: 3668

Answers (1)

Christopher Moore
Christopher Moore

Reputation: 3099

The currency pipe only accepts numbers as valid input.

If your backend is providing you a $ symbol, remove it using the slice pipe before you pass it to the currency pipe

{{ session.balance | slice : '1' | currency : 'USD' : true : '1.2-2' }}

Upvotes: 3

Related Questions