使用ng-maxlength
参照を使用します完全な詳細here
例コード
<script>
angular.module('ngMaxlengthExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.maxlength = 5;
}]);
</script>
<div ng-controller="ExampleController">
<form name="form">
<label for="maxlength">Set a maxlength: </label>
<input type="number" ng-model="maxlength" id="maxlength" />
<br>
<label for="input">This input is restricted by the current maxlength: </label>
<input type="text" ng-model="model" id="input" name="input" ng-maxlength="maxlength" /><br>
<hr>
input valid? = <code>{{form.input.$valid}}</code><br>
model = <code>{{model}}</code>
</form>
</div>
、あなたはいけない場合は、この
pp.directive("limitTo", [function() {
return {
restrict: "A",
link: function(scope, elem, attrs) {
var limit = parseInt(attrs.limitTo);
angular.element(elem).on("keypress", function(e) {
if (this.value.length == limit) e.preventDefault();
});
}
}
}]);
<input limit-to="4" type="number" class="form-control input-lg" ng-model="search.main" placeholder="enter first 4 digits: 09XX">
関連する質問がhere
おかげで見つけることができるユーザタイプ、さらに
使用をできるようにしたい:Dそれを –
@AnushaBayyaマークが役に立ったと回答した場合 – Sajeetharan
うん@確かに@Sajeetharan –