【发布时间】:2018-08-27 20:43:26
【问题描述】:
当我在表单中添加一个产品时,显示此错误。 我的代码ts:
this.products = this.ps.getProduct();
this.addform = this.fb.group({
'invoice_number': new FormControl('', [Validators.required, Validators.nullValidator]),
'Subtotal': new FormControl('', Validators.required),
'products': this.fb.array([
]),
'total': new FormControl('', Validators.required),
});
模型类:
export class Sale {
invoice_number: number;
products: Products[];
}
我的 HTML 代码:
<form [formGroup]="addform" (ngSubmit)="onaddsale()">
<div class="contant">
<div class="row">
<div class="input-field col s4">
<input formControlName="invoice_number" id="invoice_number" type="text" class="validate">
</div>
</div>
</div>
<tr formArrayName="products" class="group" style="cursor: pointer" *ngFor="let item of products; index as i" [formGroupName]="i">
<td>
<input formControlName="Subtotal" [(ngModel)]="item.Subtotal" readonly type="number" />
</td>
<td>
<input formControlName="total" [(ngModel)]="item.total" readonly type="number" />
</td>
</tr>
</form>
在我的 HTML 中不显示任何内容,也在控制台中显示我的错误。
你能建议是什么问题,如何解决这个问题?
【问题讨论】:
-
您能否将完整的控制台错误粘贴到您的问题中?
-
AddSaleFormComponent.html:83 错误错误:在 FormGroupDirective.addControl 的 setUpControl (forms.js:2300) 的 _throwError (forms.js:2432) 处找不到带有路径的控件:'products -> Quantity' (forms.js:6658) 在 FormControlName._setUpControl (forms.js:7308) 在 FormControlName.ngOnChanges (forms.js:7221) 在 checkAndUpdateDirectiveInline (core.js:12348) 在 checkAndUpdateNodeInline (core.js:13876) 在 checkAndUpdateNode ( core.js:13819) 在 debugCheckAndUpdateNode (core.js:14712) 在 debugCheckDirectivesFn (core.js:14653)
-
@raghav710 你对这个问题有什么想法吗?
-
我会尽快找到答案
标签: html angular forms typescript form-control