我有一个输入字段,我希望用户输入一个数字,所以我已经输入了一个type =“number”的输入字段.
当我使用它在1.2我没有错误
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js"></script> <script> var app = angular.module('app',[]); app.controller('MainCtrl',['$scope',function ($scope) { $scope.person = [ {"name": "Alex","pts": "10"} ]; }]); </script> <div ng-app="app"> <div ng-controller="MainCtrl"> {{person | json }}<br> name: <span ng-bind="person[0].name"></span></br> <!-- pts: <input ng-model="person[0].pts"> --> pts: <input type="number" ng-model="person[0].pts"><br? </div> </div>
http://codepen.io/anon/pen/dPKgVL
但是当我使用它在1.3我得到错误:[ngModel:numfmt],但是当我更新的数字,它似乎仍然绑定到范围.
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <script> var app = angular.module('app',"pts": "10"} ]; }]); </script> <div ng-app="app"> <div ng-controller="MainCtrl"> {{person | json }}<br> name: <span ng-bind="person[0].name"> name: <span ng-bind="person[0].name"></span></br> <!-- pts: <input ng-model="person[0].pts"> --> pts: <input type="number" ng-model="person[0].pts"> </div> </div>
http://codepen.io/anon/pen/YPvJro
我在这里做错了什么,这是不用担心的?当我试图调试其他问题时,我宁愿不要在我的控制台中出现错误
解决方法
将pts属性定义为数字而不是字符串:
var app = angular.module('app',[]); app.controller('MainCtrl',function ($scope) { $scope.person = [ {"name": "Alex","pts": 10} ]; }]);