1

当前有一个问题,当单击排序时,按行排列数组中具有 formControls 的列,数据和控件未正确更新。所有其他列都按预期更新。下面是具有 formControls 的代码:

<form [formGroup]="rackAverageForms[i]">
          <md-input-container>
            <input [formControl]="rackAverageForms[i].controls.rackAverage" #rackAverage
                   formControlName="rackAverage"
                   (keydown.tab)="validateRackAverage(rackAverage,i)" class="numeric-field" [numberOnly]="true"
                   mdInput value="{{row.chosenDateRackAverage | currency:'USD':true:'1.4-4'}}">
            <md-error><strong>{{formErrors[i].rackAverage}}</strong></md-error>
          </md-input-container>
</form>

这是排序前的截图: md-table view before trying to sort

这是排序后数据消失了: md-table view after sorted with missing data

有时会保留一个值,但大多数时候此列中的所有值都已消失,控件也已消失。请帮忙。

4

1 回答 1

1

在尝试了一些不同的事情之后,切换到使用 row.id 唯一值来查找它现在正在工作的表单控件。请参阅下面的固定 html:

       <form [formGroup]="rackAverageForms[row.id]">
          <ng-container *ngIf="row.chosenDateRackAverage > 0">
            <md-input-container>
              <input [formControl]="rackAverageForms[row.id].controls.rackAverage" #rackAverage
                     formControlName="rackAverage"
                     (keydown.tab)="validateRackAverage(rackAverage,row.id)" class="numeric-field" [numberOnly]="true"
                     mdInput value="{{row.chosenDateRackAverage | currency:'USD':true:'1.4-4'}}" >
              <md-error><strong>{{formErrors[row.id].rackAverage}}</strong></md-error>
            </md-input-container>
          </ng-container>
        </form>
于 2017-08-31T16:04:26.907 回答