假设我有以下表格:
<form #form="ngForm">
<div *ngFor="let action of member_plan.actions">
<div class="container">
<h4 class="text-sm-center black mb-3">{{findActionTitle(action)}}</h4>
<div class="col-sm-12">
<div class="form-group">
<div class="headline">Vælg tid (i dage)</div>
<input type="text" placeholder="Antal dage" class="form-control" [pattern]="numberPattern"
name="days-{{member_plan.actions.indexOf(action)}}" required
[(ngModel)]="action.time">
<li *ngIf="'days-'+member_plan.actions.indexOf(action).errors && ('days-'+member_plan.actions.indexOf(action).dirty || 'days-'+member_plan.actions.indexOf(action).touched)">
Tid kan ikke indeholde bogstaver
</li>
</div>
</div>
</div>
<hr/>
</div>
</form>
正如你所看到的,我试图添加验证,但是自从
name
必须是唯一的我如何添加验证到每个单独的输入字段?