以角度4修补行内部的值

问题描述 投票:0回答:1

如何修补我的行内的值。我有这个unit_price,如果我在select选项中选择了一个特定的成分,它会在unit_price的输入字段中修补它吗?请参阅此链接以获取代码SEE THIS LINK

onSelectIngredient(event): void {
    const formData ={
      ingredient_id: event.target.value
    }
    console.log(formData);
    this.patchValues();
  }
angular angular-reactive-forms angular4-forms
1个回答
1
投票

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);
  }

模板更改

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

link的工作示例

© www.soinside.com 2019 - 2024. All rights reserved.