ng-model throwing error on input type number in angular 1.3
Define the pts
property as a number
instead of a string
:
var app = angular.module('app', []);
app.controller('MainCtrl', ['$scope', function ($scope) {
$scope.person = [
{"name": "Alex","pts": 10}
];
}]);
Add this to fix the issue:
myApp.directive('input', [function() {
return {
restrict: 'E',
require: '?ngModel',
link: function(scope, element, attrs, ngModel) {
if (
'undefined' !== typeof attrs.type
&& 'number' === attrs.type
&& ngModel
) {
ngModel.$formatters.push(function(modelValue) {
return Number(modelValue);
});
ngModel.$parsers.push(function(viewValue) {
return Number(viewValue);
});
}
}
}
}]);