【发布时间】:2017-10-23 23:30:34
【问题描述】:
我在 2 个 angular 表中有 2 行,只有一个提交按钮,我需要帮助,因为如果 2 个表中的 2 行为空,我只能禁用提交按钮。如果只有一行为空但另一行不为空,我如何才能禁用按钮? <button type="submit" class="btn btn-primary float-right" [disabled]="!myForm.valid || myForm.controls.rows.length == 0">Save</button>
ts
this.myForm = this.fb.group({
rows: this.fb.array([]),
rows2: this.fb.array([])
});
html
<form class="form-horizontal" [formGroup]="myForm" (ngSubmit)="onCreate()" >
<div class="card-block" formArrayName="rows">
<table>
<tr *ngFor="let row of myForm.controls.rows.controls; let i = index" [formGroupName]="i">
....
</table>
</div>
<div class="card-block" formArrayName="rows2">
<table>
<tr *ngFor="let row2 of myForm.controls.rows2.controls; let i2 = index" [formGroupName]="i2">
...
</tr>
</table>
</div>
<button type="submit" class="btn btn-primary float-right" [disabled]="!myForm.valid || myForm.controls.rows.length == 0">Save</button>
</form>
【问题讨论】:
-
@SDhaliwal。它不起作用
-
用什么变量来填充行?
-
@BleachedAnus。我在上面添加了一个新文件
-
你对这些表使用 ngFor 吗?
标签: angular angular-services angular-reactive-forms angular4-forms