在 Controller 中,我向 Controller 添加一个(数字)值:
this.myValue = Number(elem.toFixed(2));
我把它放在输入表单中:
<input class="my-input"
type="number"
value={{$ctrl.myValue}}
...
>
该值是正确的,所有内容都按预期显示在屏幕上,但我在控制台中收到此警告消息:
The specified value "{{$ctrl.myValue}}" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+.\d+|.\d+)([eE][-+]?\d+)?
有什么想法可以摆脱它吗?
最佳答案
使用
$scope.myValue = 0;
在 Controller 中初始化变量。然后将其用作 -
<input type="text" ng-model="myValue" >
然后您可以使用 $scope.myValue 在 Controller 中的任何位置访问它。
关于javascript - 在 AngularJS 中显示从 Controller 附加的值时出现警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49273657/