Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get validation error value(=inputed value, but not in model) angularjs way

Tags:

angularjs

I’m trying to get user.name.length value at error message. If jQuery is used, it is realizable, but isn't there any 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>
like image 991
user2050690 Avatar asked Dec 13 '25 05:12

user2050690


1 Answers

Can you try with {{myForm.name.$viewValue.length}}, like 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>
like image 51
Rajkamal Subramanian Avatar answered Dec 15 '25 05:12

Rajkamal Subramanian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!