简体   繁体   中英

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.

Do you can transform string to number:

$scope.age = parseInt(ageString);

At the HTML:

<input type="number" name="age" ng-model="age"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM