#how to select all checkbox with ng-reflect-state ?

3 messages · Page 1 of 1 (latest)

pale ermine
#

Hi,

I'm trying to create a checkbox where when I click on it, all others are selected and when I remove the click, all are removed. In my function I managed, when clicking return all checkboxes. But they are not selected. I verified that the class that enables and disables the checkboxes is ng-reflect-state="unchecked" or "checked".

How do I select and deselect all? my cod

#
<mat-dialog-content>
  <div class="cert-list-all">
    <mat-selection-list>
      <ng-container *ngFor="let certidao of certidoes; let index = index; let last = last">
        <ng-container *ngIf="index > 0 else head_list_name1">
          <ng-container *ngIf="certidao.departamento != certidoes[index-1].departamento">
            <mat-list-option (selectedChange)="selectAll(certidao.departamento!)" [selected]="selection.hasValue()">
              <div mat-subheader>
                {{ nameOfDepartment(certidao.departamento!) }}
              </div>
            </mat-list-option>
          </ng-container>
        </ng-container>

        <ng-template #head_list_name1>
          <mat-list-option (selectedChange)="selectAll(certidao.departamento!)" [selected]="selection.hasValue()">
            <div mat-subheader>
              {{ nameOfDepartment(certidao.departamento!) }}
            </div>
          </mat-list-option>
        </ng-template>

        <mat-list-option (selectedChange)="onSelectionChange(certidao)">
          <mat-icon mat-list-icon class="folder-list">{{ iconOfDepartment(certidao.departamento!) }}</mat-icon>
          <strong>{{ certidao.numero_cpha }}</strong>
        </mat-list-option>

        <mat-divider *ngIf="!last"></mat-divider>
      </ng-container>
    </mat-selection-list>
    <div class="loading" *ngIf="loading">
      <mat-spinner mode="indeterminate" [diameter]="50"></mat-spinner>
    </div>
  </div>
</mat-dialog-content>```
#
/**
  *
  * @param departamento Number
  */
  selectAll(departamento:number) {

    var arr = Object.values(this.certidoes.filter(item => item.departamento! == departamento));
  //console.log(arr);
  
    this.selection.select(... this.certidoes.filter(item => item.departamento! == departamento));
   
    arr.forEach(function (value: any) {
      console.log(value);
    }); 
  }```