Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR TypeError: co.Number is not a function

Tags:

angular

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

like image 547
Matt Avatar asked May 13 '17 08:05

Matt


People also ask

Is not a function Type error?

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.

Is not a function JavaScript function?

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.

What is an uncaught Type error?

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.


1 Answers

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.

like image 134
gsc Avatar answered Oct 04 '22 06:10

gsc