this.myForm = fb.group({
name: ['', [Validators.required, Validators.minLength(2)]],
date: ['', [Validators.required, Validators.minLength(2)]],
address: ['', [Validators.required, Validators.minLength(2)]],
,
items: fb.array([
this.initItem(),
])
});
initItem() {
return this.fb.group({
item: [''],
itemType: [''],
amount: [''],
presentRate:this.myForm,
total:['']
});
提交表单时,此项目属性将由一个对象存储。示例对象:
item{
itemName:"name",
itemRate:1000,...}
如何使用项目对象的属性并修补我的 initItem() 方法属性中的值?我的场景就像,当用户从下拉列表中选择一个值时,项目将得到更新,我想显示从其他表单控件中的项目。例子:
<div *ngFor="let item of myForm.controls.items.controls; let i=index">
<div [formGroupName]="i">
<md2-autocomplete [items]="products"
item-text="product"
(change)="handleChange($event)"
placeholder="Product purchased"
formControlName="item"
>
</md2-autocomplete>
<md-input-container >
<input md-input placeholder="Present rate" [value]="presentRate" formControlName="presentRate" >
</md-input-container>
我想自动更新 presentRate 输入框中的值。