错误错误:名称为"products"的表单控件没有值访问器 [英] ERROR Error: No value accessor for form control with name: 'products'
本文介绍了错误错误:名称为"products"的表单控件没有值访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的项目显示此错误:
错误错误:名称为'products'的表单控件没有值访问器.
ERROR Error: No value accessor for form control with name: 'products'.
我想在Myform组件中添加一个数组Products.
I want to add an array Products in Myform component.
我有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;
}
);
}
我应该如何解决?
图错误
How should I do to fix it?
Img err
推荐答案
好吧,我遇到了类似的问题错误:没有用于表单控件的值访问器没有未指定的值访问器"
well, i was in a similar issue "ERROR Error: No value accessor for form control with unspecified "
我试图解决2天,搜索了完整的Stackoverflow,
i tried to solved it for 2 days, searched complete Stackoverflow,
最后起作用了,我做了什么
at last what worked and what i did
- 在代码中查找所有ngModel并为其添加名称属性.
- 如果已指定名称,请在其中添加"ngDefaultControl"
这篇关于错误错误:名称为"products"的表单控件没有值访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文