I am trying to multiply two strings with Angular.
<h5>{{Number(someString) * Number(someOtherString)}}</h5>
but I am getting this error:
ERROR TypeError: co.Number is not a function
How can I multiply two strings with Angular in the HTML?
Edit:
gsc pointed out that I can simply multiply the strings together.
{{'4'*'3'}}
12
However, be careful
{{'4'+'3'}}
43
This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value is not actually a function.
According to the Mozilla website for developer documents, “the TypeError object represents an error when a value is not of the expected type.” Uncaught means that the error was not caught in the catch part of the try-catch block.
Inside a component template, you don’t have access to global JavaScript objects (like Number
, window
). You can only use properties and functions from your component class (and Angular stuff, like pipes). Finally, you don’t need to invoke Number
constructor to convert your string
to number
, because JavaScript will do it for you.
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