1

I am creating a dynamic form using the ng-repeat directive and create an input with an id called 'value' like this:

<input name="value" id="{{ 'value-' + $index }}" required>

And I am trying to perform form validation on the dynamic id (ie: value-0, value-1, ...) here with no avail:

<div ng-messages="form.{{ 'value-' + $index }}.$error">
     <div ng-message="required">This Is Required!</div>
</div>

Was wondering what the syntax would look like inside that ng-messages directive. Thanks in advance.

1 Answer 1

1

Use property accessor in AngularJS expressions:

<input name="value-{{$index}}" id="{{ 'value-' + $index }}" required />
<div ng-messages="form['value-' + $index].$error">
     <div ng-message="required">This Is Required!</div>
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.