以下のコードは、入力タイプがテキストの場合にのみ機能し、タイプがnumberの場合は機能しません。angle型がinput type = "number"で機能しない
<div ng-app="myApp" ng-controller="myCtrl as model">
<input type="text" ng-model="cero" ng-decimal >
</div>
angular
.module("myApp",[])
.controller('myCtrl', function($scope){
var model=this;
})
.directive('ngDecimal', function ($parse) {
var linkFunction =function(scope, element, attrs){
element.bind("keypress", function(event) {
if(event.which === 13) {
scope.$apply(function(){
scope.$eval(attrs.format, {'event': event});
if(scope.cero===undefined || scope.cero===''){
scope.cero="0.",
event.preventDefault();
}else{
}
});
}
});
};
return{
restrict : 'A',
scope:{
cero: '=ngModel'
},
link: linkFunction
}
});
私が助けが必要なのは、タイプを番号に変更してコードを動作させることです。コードはCodePenにもあります。
あなたは問題を説明していません。 – Amy
おそらく 'scope.cero =" 0 "、" –
としようとしているかもしれません。あなたはあなたの質問を精緻化できますか? –