下面的代码的工作,只有当输入类型是文本,并且当类型是数它不工作。角指令不与输入类型工作=“号码”
<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',' –
你试图对这个指令做什么。你能详细说明你的问题吗? –