首页 > 解决方案 > Getting error "Property 'tpl' does not exist on type 'ListComponent'." using Angular material table

问题描述

I am getting the following error while implementing the angular material table.

Error:

Property 'tpl' does not exist on type 'ListComponent'.

I am explaining my code below.

<div class="mt-9">
                <table mat-table [dataSource]="dataSource" matSort (matSortChange)="sortChange($event)">

                    <tr mat-header-row *matHeaderRowDef="displayColumns(); sticky: true"></tr>
                    <tr mat-row *matRowDef="let row; columns: displayColumns();" matRipple class="element-row"
                        [cdkDetailRow]="row" [cdkDetailRowTpl]="tpl"></tr>
                </table>
                <div *ngIf="!dataSource || dataSource?.length === 0" class="text-center mt-5 text-danger">
                    <h6>No records found</h6>
                </div>
                <mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" [pageSize]="pageSize" [pageIndex]="pageIndex"
                    [length]="totalCount" (page)="pageChange($event)" showFirstLastButtons></mat-paginator>
            </div>

Here I am using [cdkDetailRowTpl]="tpl" and here that error is coming. I need some help to resolve this error.

标签: angularangular-material-5angular-material-table

解决方案


tpl应该在您的列表组件中声明

列表组件:

export class ListComponent implements OnInit {
  tpl: any;

  constructor() { }

  ngOnInit() {
  }

}

推荐阅读