Error There is no directive with “exportAs” set to “matTableExporter” when using MatTableExporter

与世无争的帅哥 提交于 2020-01-03 01:40:12

问题


From the docs example I'm trying to use the mat table exporter, this way:

<ng-container>
    <mat-card class="mat-card py-0">
        <mat-card-header class="label">
          <ng-container>
            <mat-card-title>{{titoloTabella}}</mat-card-title> 
            <button mat-button class="align-right" (click)="changeClass()">
              <mat-icon [ngClass]="(rotate)?'rotate':'no-rotate'">keyboard_arrow_down</mat-icon>
              </button>
          </ng-container>
          </mat-card-header>
  <table mat-table  matSort [dataSource]="dataSource" matTableExporter #exporter="matTableExporter">
    <ng-container *ngFor="let header of tableConfiguration.tableHeaders; let i = index" matColumnDef="{{ header.headerId }}"> 
      <th mat-header-cell mat-sort-header *matHeaderCellDef>{{ header.headerName }}</th> 

      <td mat-cell *matCellDef="let row" > {{ row[header.headerId] }} </td> 

      <ng-container *ngIf="i == 0 && header.isJoinable == 'no'">
          <td mat-footer-cell *matFooterCellDef>TOTALE</td>
      </ng-container>
      <ng-container *ngIf="i > 0">    
          <td mat-footer-cell *matFooterCellDef>{{ tableFooter[header.headerId] }}</td>
    </ng-container>
    </ng-container>
    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns;" [ngClass]="(collapsed)? 'collapsed-rows': 'no-collapsed-rows' "></tr>
    <tr mat-footer-row *matFooterRowDef="displayedColumns"></tr>
  </table>
</mat-card>
<button (click)="exporter.exportTable('xlsx')"> EXPORT</button>
</ng-container>

I've imported the MatExporterTabModule in my app.module.ts, in providers section. But this is the error I'm getting when I run the application:

RROR Error: Uncaught (in promise): Error: Template parse errors: There is no directive with "exportAs" set to "matTableExporter" ("


回答1:


You have to import this module in "imports" section instead of providers.



来源:https://stackoverflow.com/questions/57969084/error-there-is-no-directive-with-exportas-set-to-mattableexporter-when-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!