我需要使用ng-model访问/使用min和max,因为我没有表单名称和输入字段名称来访问错误/有效范围。
<input type="text" ng-minlength="10" ng-maxlength="30" ng-model="value.x" >
<p ng-if="value.x.$error" class="help-block">Please enter above {{minlength}} characters</p>
<p ng-if="value.x.$error" class="help-block">Please enter below {{maxlength}} characters</p>
答案 0 :(得分:0)
使用value.x
<input type="text" ng-minlength="10" ng-maxlength="30" ng-model="value.x" >
<p ng-if="value.x.length < 10" class="help-block">Please enter above {{minlength}} characters</p>
<p ng-if="value.x.length > 30" class="help-block">Please enter below {{maxlength}} characters</p>
答案 1 :(得分:0)
我猜这是ng-minlength和ng-maxlength的问题。他们没有在我的工作。请尝试下面对我有用的代码。
<input type="text" ng-model="value.x" />
<p ng-if="value.x.length < minlength" >Please enter above {{minlength}} characters</p>
<p ng-if="value.x.length > maxlength" >Please enter below {{maxlength}} characters</p>
Angularjs
$scope.value = {x:10};
$scope.minlength = 5;
$scope.maxlength = 10;