I need to precede a value pulled from JSON with '$'. How do I do this?
I want
<span ng-model="item.value"></span>
to render $12.34, given that in the model the value of item.value = 12.34
Thanks to @JBNizet I found the answer! I posted below, in case this may help someone else in the future.
<span ng-bind="item.value | currency:USD$:2"></span>
I had to change 'ng-model' to 'ng-bind' and add the currency filter. For other newbies struggling with this - ng-model is two-way data binding, used when you user will be making changes to the data (via a form input for example). ng-bind is one-way data binding for pulling data, data that won't be changed, from the model.
Filters cannot be applied to ng-model; you instead create a formatter.
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With