Reputation: 9247
Is there any way to check max length in angular ? For example if i have this field:
<input type="text" class="form-control font28 centerText" ng-model="ticketPin" maxlength="10" only-digits mask="9999999999" restrict="reject" clean="true" />
can i say something like
if($scope.ticketPin.maxlength == 10)
{...}
Upvotes: 0
Views: 1371
Reputation: 1919
You will need to use jQuery:
$('input[ng-model="ticketPing"]').attr('maxlength');
It is generally not a good idea to access DOM elements in only directives, not services or controllers.
Upvotes: 0
Reputation: 31761
You could access the DOM with jQuery or vanilla JS in your controller, but this is generally frowned up in Angular. I suppose a more Angulary way of doing it would be to bind a variable to ng-maxlength
.
$scope.myScopeVariable = 12;
View:
<input type="text" ng-maxlength="myScopeVariable" ... />
Upvotes: 1