从角度6中获得重复控制的值

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

如何从角度重复控制中获取值6

我试图在TS文件中读取此表单字段的值,请帮助我该怎么做

这是重复块,您可以单击添加,它将再创建一个控件组

<div *ngIf="subTask.value==5 && subTask.value!=null" formArrayName="itemRows">
        <div *ngFor="let itemrow of taskfrm.controls.itemRows.controls; let i=index" [formGroupName]="i">
          <!-- Border START -->
          <div class="add-new-task-border">
            <mat-form-field class="example-full-width">
              <mat-select placeholder="Logical Oprater">
                <ng-container *ngFor="let relationaOpt of relationalOpraters">
                  <mat-option *ngIf="relationaOpt.operatorsType==='logical'" [value]="relationaOpt.id">
                    {{relationaOpt.operator}}
                  </mat-option>
                </ng-container>
              </mat-select>
            </mat-form-field>

            <mat-form-field class="two-way-banding">
              <mat-select placeholder="DataElement 1">
                <mat-option *ngFor="let dataElement of dataElementList" [value]="dataElement.dataElementID">
                  {{dataElement.dataElementName}}
                </mat-option>
              </mat-select>
            </mat-form-field>

            <mat-form-field class="two-way-banding eta-margin-two-way">
              <mat-select placeholder="Relational Oprater">
                <ng-container *ngFor="let relationaOpt of relationalOpraters">
                  <mat-option *ngIf="relationaOpt.operatorsType==='relational'" [value]="relationaOpt.id">
                    {{relationaOpt.operator}}
                  </mat-option>
                </ng-container>
              </mat-select>
            </mat-form-field>
            <mat-form-field class="two-way-banding">
              <mat-select placeholder="DataElement 2">
                <mat-option *ngFor="let dataElement of dataElementList" [value]="dataElement.dataElementID">
                  {{dataElement.dataElementName}}
                </mat-option>
              </mat-select>
            </mat-form-field>
          </div>
          <!-- Border END -->
        </div>
      </div>
      <button *ngIf="subTask.value==5 && subTask.value!=null" style="float:right;" type="button" mat-icon-button color="primary"
        (click)="addNewRow()">
        <mat-icon>add_circle</mat-icon>
      </button>
      <button *ngIf="subTask.value==5 && subTask.value!=null" style="float:right;" type="button" mat-icon-button color="primary"
        (click)="addNewRow()">
        <mat-icon>remove_circle</mat-icon>
      </button>

如果您对此有任何疑问,请告诉我

javascript angular typescript angular-material
1个回答
1
投票

您需要在表单数组中维护索引:

form.controls.itemRows.controls[i].controls.name.value

HTML:

<div *ngIf="subTask.value==5 && subTask.value!=null" formArrayName="itemRows">
<div *ngFor="let itemrow of taskfrm.controls.itemRows.controls; let i=index" [formGroupName]="i">

    <mat-form-field class="col-md-4">
        <input matInput maxlength="20" 
          formControlName="name">
    </mat-form-field>
</div>

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