角分量上的2种形式

时间:2018-07-28 22:50:23

标签: angular

我的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>

我的问题是,在第一个表单上按保存会触发对第二个表单的验证-如何将表单分开?

1 个答案:

答案 0 :(得分:1)

位置表格中存在拼写问题,请更改:

 int last = (list.size() - 1);
 int secondToLast = (list.size() - 2);

(ngSubmit)="location.form.valid && saveLocations(locations)"

在这里查看您的示例以所需的方式工作:

https://stackblitz.com/edit/angular-8sc4cr