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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With