下面的代碼的工作,只有當輸入類型是文本,並且當類型是數它不工作。角指令不與輸入類型工作=「號碼」
<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',' –
你試圖對這個指令做什麼。你能詳細說明你的問題嗎? –