Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS input type number with string model

I am getting an error message due to an input field I have. It is of type "number" but the actual model is a string. Reason behind this is, that my ngModel value is used in other parts of the application.

However for just one Input Field I need to restrict this as only using numbers.

What is the easiest way to achieve this, without changing the type of ngModel.

like image 520
user5417542 Avatar asked Aug 28 '26 20:08

user5417542


1 Answers

Do you can transform string to number:

$scope.age = parseInt(ageString);

At the HTML:

<input type="number" name="age" ng-model="age"/>
like image 77
Diogo Machado Avatar answered Aug 30 '26 11:08

Diogo Machado