FormGroup should used be at mat-row instead of using it in every cell

121 Views Asked by At

I have used [formGroup]="element" at every mat-cell, it's like using the same [formGroup] for every mat-cell. Is there a better way to use [formGroup] only once within formArray at mat-row itself? Here is the https://stackblitz.com/edit/angular-material-table-with-form?file=app%2Fapp.component.html example.

Instead of using formGroup for mat-cell, use it at mat-row.

<mat-cell *matCellDef="let element" [formGroup]="element">
  <mat-form-field floatLabel="never">
    <mat-select
      formControlName="userId"
      (selectionChange)="onUserChange($event, element)"
      required
    >
      <mat-option *ngFor="let user of users" [value]="user.id">
        {{ user.username }}
      </mat-option>
    </mat-select>
  </mat-form-field>
</mat-cell>

I want to use it likewise:

<mat-row
  *matRowDef="let row; columns: displayedColumns;"
  [formGroup]="element"
></mat-row>
0

There are 0 best solutions below