我的项目显示此错误:
Error错误:没有价值存取的表单控件名称为:“产品”。
我想在MyForm的组件添加的阵列产品。
我有2个问题:
- 当我点击的按钮,我看到这个错误。
- 我的产品阵列进来顺序表,但是当注册,该数组为空。 我的源代码。
HTML代码:
<form [formGroup]="Myform" (ngSubmit)="onaddMyForm()">
<div class="contant">
<div class="input-field col s4">
<div class="input-field col s12">
<select formControlName="client_id" id="client_id" materialize="material_select" [materializeSelectOptions]="client">
<option value="" disabled selected>ClientName</option>
<option *ngFor="let item of client" [value]="item.client_id">{{item.clientName}}</option>
</select>
</div>
<br>
<div class="row">
<div class="input-field col s12">
<label for="total">total:</label>
<input formControlName="total" id="total" type="text" class="validate">
</div>
</div>
</div>
</div>
<br>
<table formControlName="products" align="center" class="table table-bordered table-hover">
<thead>
<tr style="color:black;">
<th>Price</th>
<th>Quantita</th>
<th>Subtotale</th>
</tr>
</thead>
<tbody>
<tr [routerLink]="i" class="group" style="cursor: pointer" *ngFor="let item of products; let i=index">
<td>{{item.Price}}</td>
<td>{{item.Quantita}}</td>
<td>{{item.Subtotale}}</td>
</tr>
</tbody>
</table>
<br>
<hr>
<br>
<div id="add_homebox_button_container" class="row" style="float: right;">
<button id="add_client_button" type="submit" class="btn waves-effect waves-light">
Register
</button>
</div>
</form>
我的TS码:
我的构造函数:
constructor(
private router: Router,
private fb: FormBuilder,
private ss: ws,
) {
// I create the formGroup
this.Myform = new FormGroup({
'client_id': new FormControl('', Validators.required),
'products': this.fb.array([]),
'total': new FormControl('', Validators.required)
});
}
//My function that post in ws My form Value
onaddMyForm() {
this.loading = true;
let newprod = new Product(
this.Myform.value
);
console.log(newprod)// in console my array is empty
this.ss.prodcreate(newprod).subscribe(
result => {
if (result === true) {
Materialize.toast('Prod saved successfully', 4000);
} else {
this.loading = false;
}
},
error => {
this.loading = false;
}
);
}
我应该怎么做才能解决这个问题?
图犯错