I'm trying to do a simple textarea with "so many chars remaining" along with validation. when I use ng-maxlength to validate my form, it resets my charcount as soon as the length hits the max length. Here's the plunkr Any workarounds?
<body ng-controller="MainCtrl">
<div ng-form="noteForm">
<textarea ng-maxlength="15" ng-model="result"></textarea>
<p>{{15 - result.length}} chars remaining</p>
<button ng-disabled="!noteForm.$valid">Submit</button>
</div>
</body>
When your textarea exceeds 15 characters,
result
becomesundefined
— that's just how theng-min/maxlength
directives work. I think you'll have to write your own directive. Here is a directive that will block input after 15 characters:fiddle
Update: to allow more than 15 characters, but disable the submit button when the count exceeds 15:
fiddle