再会。
我寻找了解决方案,即使有一个与我所问的类似的问题,我相信这个问题更独特一些,而不是重复。
这是我的 html 表单:
<div class="form-group col-md-6" formGroupName="schema">
<div formArrayName="currencies">
<input type="text" class="form-control" id="percentage" formControlName="percentage" placeholder="Discount %*" required>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的 ts formBuilder。
this.createPromo = this.fb.group({
type: ['promotion'],
name: ['', Validators.required],
description: ['', Validators.required],
enabled: ['', Validators.required],
promotion_type: ['', Validators.required],
start: ['', Validators.required],
end: ['', Validators.required],
schema: this.fb.group({
currencies: this.fb.array([
this.fb.group({
percentage: '',
currency: 'ZAR'
})
])
}),
});
Run Code Online (Sandbox Code Playgroud)
所以我希望我的表单作为分组数组提交。然而,控制台中的错误如下Cannot find control with path: 'schema -> currencies -> percentage',因此percentage即使我输入了一个数字,我也无法将我的表单提交为空。