6

I'm trying to use ng-maxLength directive to give a variable max-length for my inputs.

function ValidatorCtrl($scope, $timeout) {
  $scope.name = "Star";
  $scope.$metadata={};
  $scope.$metadata.isRequired = true;
  $scope.$metadata.maxLength=5;
}


     <input type="text" ng-model="name" ng-maxlength="$metadata.maxLength"   
ng-required="$metadata.isRequired" name="name" /> 

But it doesn't seems to be working as expected. When it is applied the model binding for the same variable is not working. Here is my plunker

If I remove ng-maxLength ng-required is going to work as expected , otherwise ng-required is also not working.

3
  • 4
    I think it's a bug github.com/angular/angular.js/issues/1405 if you put directly 5 it works it seems ng-maxlength="{{$metadata.maxLength}}" to work Commented Apr 2, 2014 at 10:54
  • 1
    ng-maxlength="{{$metadata.maxLength}}" seems to be working Commented Apr 2, 2014 at 10:59
  • Yeah seems like a bug. Commented Apr 2, 2014 at 11:00

1 Answer 1

2

ng-maxlength does not take scope values.
Traditionally ng-maxlength is used as such ng-maxlength="3". You can either add curly braces around your scope value or create a directive that binds scope value inside ng-maxlength.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.