I need some help. I'm doing some validation on an input element and would like to set a dynamic error message in javascript. I am aware of the following way to do this, but my situation has become somewhat complex. The message itself needs to be dynamic. For example, I may want to show the position within a string (i.e. 9) where there is an invalid character.
some html...
<input type="text" name="firstName" ng-model="data.firstName" validate-directive >
<div ng-show="employmentForm.firstName.$invalid">
<small class="error" ng-show="form.firstName.$error.err1">invalid</small>
<small class="error" ng-show="form.firstName.$error.err2">{{something dynamic}}</small>
</div>
some javascript..
.directive('validate-directive', function() {
...
ctrl.$setValidity('err2', false);
//set a custom message to be shown
}
Any suggestions on how I might approach this?