ngMinlength adds the minlength validator
to ngModel
.
It is most often used for text-based input
controls, but can also be applied to custom text-based controls.
The validator sets the minlength
error key if the ngModel.$viewValue
is shorter than the integer obtained by evaluating the Angular expression given in the
ngMinlength
attribute value.
minlength
attribute is used, with two
differences:
ngMinlength
does not set the minlength
attribute and therefore HTML5 constraint
validation is not available.
ngMinlength
value must be an expression, while the minlength
value must be
interpolated.
<ANY>
...
</ANY>
<script>
angular.module('ngMinlengthExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.minlength = 3;
}]);
</script>
<div ng-controller="ExampleController">
<form name="form">
<label for="minlength">Set a minlength: </label>
<input type="number" ng-model="minlength" id="minlength" />
<br>
<label for="input">This input is restricted by the current minlength: </label>
<input type="text" ng-model="model" id="input" name="input" ng-minlength="minlength" /><br>
<hr>
input valid? = <code>{{form.input.$valid}}</code><br>
model = <code>{{model}}</code>
</form>
</div>