angularJS 오류: [ngModel: numfmt]http://errors.angularjs.org/1.4.1/ngModel/numfmt?p0=333

10066 단어 AngularJS
<!doctype html>
<html ng-app="a10086">
<head>
    <meta charset="utf-8">
    <script src="angular.min.js"></script>
</head>
<body>

<pre>
stringToNumber2          ,
  html       ,html                 , stringToNumber2   stringtonumber2,
    :Error: ngModel:numfmt Model is not of type `number`。。     :         ,    (    ) html        (  )   
 html       :string-to-number2    。。ng   。
</pre>
<div ng-controller="kkc">
 <input type="date"/>
    <input type="number" string-to-number ng-model="cc.a"/> {{ cc.a }}
    :<input type="number" stringToNumber2 ng-model="cc.b"/> {{ cc.b }}

</div>

</body>
</html>
<script>

angular.module('a10086',[])
.controller('kkc',function($scope){
    $scope.cc={
        a:'222',b:'333'
    }//         a b    ,         。
}).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 parseInt(value);
            });
        }
    };
}).directive('stringToNumber2', function() {
    return {
        require: 'ngModel',
        link: function(scope, element, attrs, ngModel) {
            ngModel.$parsers.push(function(value) {
                return '' + value;
            });
            ngModel.$formatters.push(function(value) {
                return parseInt(value);
            });
        }
    };
});
</script>

 AngularJS v1.4.1
input type="number":    ipad         ,       , type="text"       ;         
$scope.cc={
        a:'222',b:'333'
    }  cc.a=222,cc.b=333     ,             ,        ,       。。
, :stringToNumber2, html stringToNumber2, , stringtonumber2, “333” , :stringToNumber, html 2 :1 string-to-number,2 。。

좋은 웹페이지 즐겨찾기