Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度4中行内的修补值_Angular_Angular Reactive Forms_Angular4 Forms - Fatal编程技术网

Angular 角度4中行内的修补值

Angular 角度4中行内的修补值,angular,angular-reactive-forms,angular4-forms,Angular,Angular Reactive Forms,Angular4 Forms,如何修补行内的值。我有一个单位价格,如果我在选择选项中选择了一种特定的成分,它会在单位价格的输入字段中修补它?请查看此链接了解代码 对patchValue方法进行以下更改 patchValues(id,i) { let x = (<FormArray>this.addForm.controls['rows']).at(i); console.log(x); x.patchValue({ unit_price: this.ingredients[

如何修补行内的值。我有一个单位价格,如果我在选择选项中选择了一种特定的成分,它会在单位价格的输入字段中修补它?请查看此链接了解代码


patchValue
方法进行以下更改

 patchValues(id,i) {
    let x = (<FormArray>this.addForm.controls['rows']).at(i);
    console.log(x);

    x.patchValue({
      unit_price: this.ingredients[id - 1].price
    });
  }



  onSelectIngredient(event,i): void {
    const formData = {
      ingredient_id: event.target.value
    }
    console.log(formData,i);
    this.patchValues(event.target.value,i);
  }
patchvalue(id,i){
设x=(this.addForm.controls['rows']).at(i);
控制台日志(x);
x、 补丁价值({
单价:此.配料[id-1].价格
});
}
OnSelectComponent(事件,i):无效{
常量formData={
成分标识:event.target.value
}
console.log(formData,i);
这个.patchValues(event.target.value,i);
}
模板更改

<select (change)="onSelectIngredient($event,i)" class="form-control" formControlName="ingredient_id"> // to get the row id
//获取行id

中的工作示例您能解释一下这一行的含义吗?“this.components[id-1].price”。你为什么写“[id-1]”?谢谢,因为模板中的行数从1开始,而我们的数组从0开始,这就是@Joseph的原因
<select (change)="onSelectIngredient($event,i)" class="form-control" formControlName="ingredient_id"> // to get the row id