将数组的所有对象的角度反应形式setValue放入FromControl

时间:2019-03-23 17:46:52

标签: javascript typescript angular5 angular-reactive-forms

我的对象看起来像:

[
 {
    "Material_Name": "M-ACTIVATE B",
    "HS_Code": 291811009999,
    "chemical_exract": [
      {
        "Material_Name": "HYDROCHLORIC ACID",
        "CAS_No": "7647-01-0",
      },
      {
        "Material_Name": "Stannous chloride",
        "CAS_No": "8987-04-2",
      }
    ],
    "Supplier_Name": "MacDermid",
    "By_Sea": 1200,
    "By_Air": 300,
    "Total": 1500,
  },
  {
    "Material_Name": "M-FORMALDEHYDEB",
    "HS_Code": 291211000000,
    "chemical_exract": [
      {
        "Material_Name": "Formaldehyde",
        "CAS_No": "50-00-0",
      }
    ],
    "Supplier_Name": "MacDermid",
    "By_Sea": 1200,
    "By_Air": 300,
    "Total": 1500,
  },
  ...
]

我想显示所有chemical_exract对象并将它们显示到我的formControl productDescription

那是我的尝试:

 autoContinueProductId(productId: string) {

  let findedOb = this.jsonData.find(p => p.HS_Code == productId);
  let chemicalExtract = findedOb["chemical_exract"];

  this.myForm.controls["products"].patchValue({
     productDescription: productDescription: `Material Name is : 
     ${chemicalExtract.Material_Name} and Cas Number is : 
     ${chemicalExtract.CAS_No} ` ,

  });

}

但是我只得到了ChemicalExract数组的最后一个对象。

我想要的是逐个显示chemicalExract数组的所有对象  在我的控制表单中:

材料名称是:盐酸和CAS号是:7647-01-0

材料名称是:氯化亚锡,CAS号是:8987-04-2

这就是我的HTML:

 <!-- productDescription -->
                        <div class="row">
                          <div class="col">
                            <mat-form-field class="example-full-width">
                              <textarea
                               rows="10"
                                matInput
                                formControlName="productDescription"
                                id="productDescription"
                                placeholder="Description In Arabic"

                              ></textarea>
                            </mat-form-field>
                          </div>
                        </div>

请任何人可以帮助我,谢谢。

0 个答案:

没有答案