Aminadav Glickshtein
Aminadav Glickshtein

Reputation: 24600

$valid inside ng-repeat in AngularJS

I know how to show errors in angular js in case the all form input are invalid. I also know how to show message if one field is invalid.

The Question is how to show a message inside ng-repeat of items, when only some of the items are invalid.

<form name=form>  
  <div ng-repeat="item in items">
    <textarea ng-model="item.value" name="item">
    <div ng-show="form.name.$invalid">
              I want to show this message if this   textarea is invalid
    </div>
  </div>

  <div ng-show="form.$invalid">You have error in your form</div>
</form>

Please see this above line <div ng-show="form.name.$invalid"> it will show the message x times, but I want to show the invalid message only for the invalid input.

Upvotes: 0

Views: 190

Answers (1)

Joseph
Joseph

Reputation: 119847

Wrap everything under the ng-repeat with a <div> that has ng-form.

ngForm

Nestable alias of form directive. HTML does not allow nesting of form elements. It is useful to nest forms, for example if the validity of a sub-group of controls needs to be determined.

https://docs.angularjs.org/api/ng/directive/ngForm

Upvotes: 3

Related Questions