0

Why does this work:

<span>${{10 + 20}}</span>
<!-- <span>$30</span> -->

But this doesn't work:

<span>${{cart.subtotal + cart.taxTotal}}</span>
<!-- <span>$1020</span> -->

It seems that the properties from the component are passed to the template as strings, irregardless that they are typed as numbers on the component itself.

2
  • Can you throw together a quick plunkr? I ran your code with no issues. Commented Jun 20, 2017 at 2:35
  • Are you sure they're of the number type? Commented Jun 20, 2017 at 2:57

1 Answer 1

1

If you are using $ angular tries to parse it as a template expression. How ever you can use the currency pipe to display the currency on your template

<span>{{cart.subtotal + cart.taxTotal | currency:'USD':true}}</span>

LIVE DEMO

Sign up to request clarification or add additional context in comments.

3 Comments

Get an InvalidPipeArgument: '1020' for pipe 'CurrencyPipe'. Even tried taking the $ out from in front of the brackets and that didn't work
what version you are using
If you are using $ angular tries to parse it as a template expression - what do you mean by template expression with regards to $? Can point to specific documentation place where $ is explained in regards to the template expression?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.