Skip to content Skip to sidebar Skip to footer

Dynamic Ng-minlength / Ng-maxlength

I'm trying to add dynamic min/maxlength attributes using ng-minlength && ng-maxlength. For example, And

Solution 1:

You need to add an ng model. Keep in mind that this will not limit the input. Only give you classes when the max and min values are valid/invalid.

<input type="text" ng-model="number" ng-minlength="myMin" ng-maxlength="myMax">

app.controller('MainCtrl', function($scope) {
  $scope.myMin = 1;
  $scope.myMax = 5;
  $scope.number = 1;
});

If you just want to limit the input you can use regular html:

<inputtype="text" ng-model="number" maxlength="{{myMax}}" >

I created a fork with both examples.

Post a Comment for "Dynamic Ng-minlength / Ng-maxlength"