types - In AngularJS 1.6, how to avoid a error [ngModel:numfmt] even if ng-if is correct? -
i have weird bug. need display input[type="text"] or input[type="number"] depending of value in condition ng-if :
{{ column.item === 'number' }} <input ng-model="inserts[pointers.headings.content.tabinserts - 1].dados[0][columnid].value" class="form-control" placeholder="{{ column.default }}" ng-if="column.item === 'text' && !column.extra"/> <input ng-model="inserts[pointers.headings.content.tabinserts - 1].dados[0][columnid].value" class="form-control" type="number" placeholder="{{ column.default }}" ng-if="column.item === 'number' && !column.extra" /> i have weird result : ... when inserts[pointers.headings.content.tabinserts - 1].dados[0][columnid].value string after previous 1 number.
even if {{ column.item === 'number' }} display correctly "false" , second input not displayed, angularjs continue send error :
error: [ngmodel:numfmt] http://errors.angularjs.org/1.6.4/ngmodel/numfmt?p0=john
why ? should not try this. has got idea ?
i think enough info error: https://docs.angularjs.org/error/ngmodel/numfmt?p0=john
expected
johnnumber
you can reproduce as:
<tr ng-repeat="x in ['jhon']"> <td> <input type="number" ng-model="x" /> {{ x }} : {{ typeof(x) }} </td> </tr> vm424 angular.min.js:124 error: [ngmodel:numfmt] http://errors.angularjs.org/1.6.7-build.5459+sha.21a2f4b/ngmodel/numfmt?p0=jhon @ vm424 angular.min.js:7 @ array.<anonymous> (vm424 angular.min.js:187) @ vm424 angular.min.js:192 @ m.$digest (vm424 angular.min.js:147) @ m.$apply (vm424 angular.min.js:150) @ vm424 angular.min.js:22 so sure inserts[pointers.headings.content.tabinserts - 1].dados[0][columnid].value number , not jhon
if use number string, can use string-to-number directive:
.directive('stringtonumber', function() { return { require: 'ngmodel', link: function(scope, element, attrs, ngmodel) { ngmodel.$parsers.push(function(value) { return '' + value; }); ngmodel.$formatters.push(function(value) { return parsefloat(value); }); } }; }); html
<table> <tr ng-repeat="x in ['jhon', '2']"> <td> <input type="number" string-to-number ng-model="x" /> {{ x }} : {{ typeof(x) }} </td> </tr> </table>
Comments
Post a Comment