Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在ng模型上应用parseFloat_Javascript_Html_Angularjs_Angularjs Ng Model - Fatal编程技术网

Javascript 在ng模型上应用parseFloat

Javascript 在ng模型上应用parseFloat,javascript,html,angularjs,angularjs-ng-model,Javascript,Html,Angularjs,Angularjs Ng Model,我试图使用ng模型在输入字段上打印浮点值。但它没有显示出来。如果我使用值而不是ng模型,那么它就会显示出来 这是我的密码: <input id="cost" name="cost" type="number" ng-model="parseFloat(cost_per_month)"> 您不必在控制器上使用parseFloat,您可以使用数字过滤器以所需格式显示模型变量 <input id="cost" name="cost" type="number" ng-model="

我试图使用ng模型在输入字段上打印浮点值。但它没有显示出来。如果我使用值而不是ng模型,那么它就会显示出来

这是我的密码:

<input id="cost" name="cost" type="number" ng-model="parseFloat(cost_per_month)">

您不必在控制器上使用parseFloat,您可以使用数字过滤器以所需格式显示模型变量

<input id="cost" name="cost" type="number" ng-model="cost_per_month | number:2">


从控制器中删除parseFloat,并按所述更改代码;但是我看不到值。将类型改为文本而不是数字很有效。是的,它应该始终是一个字符串,如果答案有帮助,请标记,但我希望输入类型为数字。
$scope.selectedcost = parseFloat(orgprojects.cost_per_month);
<input id="cost" name="cost" type="number" ng-model="cost_per_month | number:2">