I have ng-repeat for an attribute list and you want to display error messages for each input. For the pattern error, I also want to show which specific regular expression it needs to match.
Can I access the input template? I know that I can add an attribute containing a regular expression, but I would like to know if there is an angular way somehow.
(This is a simplified example, regular expressions may differ for different attributes)
<form name="form">
<div data-ng-repeat="(attributeName, attributeMetaData) in configuration.metaData">
<input data-ng-model="configuration[attributeName]" type="text" name="{{attributeName}}" data-ng-pattern="/^[0-9][0-9]:[0-9][0-9]$/">
<span data-ng-show="form[attributeName].$error.pattern && form[attributeName].$dirty">
Please check your input format [pattern should go here]
</span>
</div>
</form>
jsFiddle: http://jsfiddle.net/lisapfisterer/ndu2g0ev/
source
share