我的Angular 6组件中有2种单独的形式:
第一个:
<form name="form" (ngSubmit)="rules.form.valid && saveRules(rules)" #rules="ngForm" novalidate>
<input id="distance" type="number" required name="distance" [(ngModel)]="model.distance" #distance="ngModel" [ngClass]="{ 'is-invalid': rules.submitted && !distance.valid }">
<div *ngIf="rules.submitted && !distance.valid" class="invalid-feedback">
Minimum Distance is required.
</div>
<button *ngIf="!isRequesting" type="submit">Save</button>
</form>
第二个:
<form name="form" (ngSubmit)="location.form.valid && saveLocations(locations)" #locations="ngForm" novalidate>
<input id="location" type="text" required name="location" [(ngModel)]="model.location" #location="ngModel" [ngClass]="{ 'is-invalid': locations.submitted && !location.valid }">
<div *ngIf="locations.submitted && !location.valid" class="invalid-feedback">
Location is required.
</div>
<button type="submit">Save</button>
</form>
我的问题是,在第一个表单上按保存会触发对第二个表单的验证-如何将表单分开?
答案 0 :(得分:1)
位置表格中存在拼写问题,请更改:
int last = (list.size() - 1);
int secondToLast = (list.size() - 2);
到
(ngSubmit)="location.form.valid && saveLocations(locations)"
在这里查看您的示例以所需的方式工作: