Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular set ng-minlength from controller does not work

Here is the controller:

    function Ctrl($scope) {
      $scope.text = 'guest';
      $scope.word = /^\w*$/;
      $scope.min_length = 4;
    }

Here is the view:

    <form name="myForm" ng-controller="Ctrl">
      Single word: 
      <input type="text" name="input" ng-model="text"
             ng-pattern="word" ng-minlength="min_length" required />
      ...
    </form>

The ng-minlength="min_length" won't trigger the minlength error except I explicitly write ng-minlength="4". However, ng-pattern="word" works fine.

Here is the jsfiddle link

Is it because I am doing wrong or there is way to get around?

like image 773
sliter Avatar asked Jul 07 '26 22:07

sliter


1 Answers

Here is how you do it with ng-minlength

<input ng-minlength="{{ min_length }}" />

Here it is working

jsFiddle link

like image 123
SoEzPz Avatar answered Jul 09 '26 18:07

SoEzPz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!