0

HTML

<ng-container matColumnDef="view">
    <mat-header-cell *matHeaderCellDef mat-sort-header>View</mat-header-cell>
       <mat-cell *matCellDef="let element; let i=index"> 
          <mat-checkbox formControlName="view" (change)=updateCheckedList(element)>
         </mat-checkbox>
       </mat-cell>
</ng-container>  ```

**TS**

view = [true,false,false,true]

createRoleForm(): FormGroup
  {
      return this._formBuilder.group({
          id              : [this.role.id],
          name            : [this.role.name],
         // view : 

      });
  }

I need to check the check boxes which are in the material table(view column) according to values of view list.

Abhishek
  • 1,742
  • 2
  • 14
  • 25
Iroshm
  • 11
  • 2

1 Answers1

-2

you cant do like this because your form Controller is having only one control fot the view so you need to you ng model it helps to you like this

    <ng-container matColumnDef="view">
        <mat-header-cell *matHeaderCellDef mat-sort-header>View</mat-header-cell>
           <mat-cell *matCellDef="let element; let i=index"> 
              <mat-checkbox [(ngModel)]="element.checked" 
               [ngModelOptions]="{standalone: true}" 
               (change)=updateCheckedList(element)>
             </mat-checkbox>
           </mat-cell>
</ng-container>

inside the element use create a attribute called checked that's it

way 2 - if you want to do with an form controlled you need to use form array that's it

Sangar Lal
  • 50
  • 3