How to get the value of the validation error (= entered value, but not in the model) Angular way
I'm trying to get the value of user.name.length in the error message. If jQuery is used it is doable, but isn't there a method unique to Angularjs?
<form novalidate name="myForm" ng-submit="addUser()">
<p>Name:
<input type="text" name="name" ng-model="user.name" required ng-minlength="5" ng-maxlength="8">
<span ng-show="myForm.name.$error.minlength">{{user.name.length}} too short!</span>
+3
source to share
2 answers
Can you try with {{myForm.name.$viewValue.length}}
as below:
<input type="text" name="name" ng-model="user.name" ng-minlength="5" ng-maxlength="8" />
<span ng-show="myForm.name.$error.minlength">{{myForm.name.$viewValue.length}} too short!</span>
<span ng-show="myForm.name.$error.maxlength">{{myForm.name.$viewValue.length}} too long!</span>
+6
source to share