如何在Angular 6中获取动态行数据

时间:2019-05-31 12:52:32

标签: angular

我有一个基于resultStored(array)的动态表,它将创建行,但是我无法在组件内找到每一行的值。 总是获取最后一行的值。我想是因为formControlName。请帮我怎么办???

table.html

<tbody>
        <tr *ngFor="let data of resultStored;let i = index;">
          <td>{{data?.tbl_medicine?.name}}</td>
          <td>{{data?.duration}} {{data?.tbl_duration?.durationType}}</td>
          <td>
            <div class="row supplayRow">
              <div class="col-md-2">
                <label class="chkBox">
                  <input type="checkbox"  (change)="UpdateSupply(data.id,$event,data)" formControlName="is_partial">
                  <span class="checkmark"></span>
                </label>
              </div>
              <div class="col-md-4">
                <input type="text" class="chkInput" placeholder="xxx"  formControlName="durationSupply">
              </div>
              <div class="col-md-6">
                <select class="form-control" type="text" name="duration"  formControlName="durationSupplyTypeId">
                  <option *ngFor="let durationData of durationValueList" value="{{durationData?.id}}">
                    {{durationData?.durationType}}</option>
                </select>
              </div>
            </div>
          </td>
        </tr>            
      </tbody>

table.ts

addMedicineSupply(form:any,i){
console.log(this.rows.value)
this.resultStored.forEach(val=>{
   let data={
    patientMedicationId: 1,
    is_partial: val.this.medicineSupply.get("is_partial").value,
    durationSupply: this.medicineSupply.get("durationSupply").value,
    durationSupplyTypeId: this.medicineSupply.get("durationSupplyTypeId").value
  }
  console.log(data,"data object");
  let supply:any=[];
  supply.push(data);
  console.log(supply,"suply===");
})

// this._apiService.postMedicineSupply(supply)

}

0 个答案:

没有答案