javascript - ng-model value is always String type, even entered value is a number -
<div> <input type="text" ng-model="test"/> </div>
"test" value string type, if entered number valid case. still want exact data type.
can suggest me way find data type, if enter value number data type should "number", , if enter value "abc" data type should "string" , etc.
in short use same html texture , data type of entered value
you're going have post bit of code give example, otherwise it's going difficult give answer. suspect it's because of bad html, i.e.,
<input type="text" />
the above return 'string'.
<input type="number" />
the above return 'number'. code set correctly?
edit: if put without caring 'type' (bad html) check type in controller when you're massaging data. i.e., (using lodash example) these 2 examples:
if (_.isstring(value)) { } if (_.isnumber(value)) { }
or native javascript use 'typeof'.
another thought it, if have choice of type="text", in controller use regex on incoming string, looking numbers.
if (value.match(/^\d+$/)) { // should 'number'; }
Comments
Post a Comment