【问题标题】:Getting error "Property 'tpl' does not exist on type 'ListComponent'." using Angular material table收到错误“类型'ListComponent'上不存在属性'tpl'。”使用 Angular 材质表
【发布时间】:2019-12-27 05:21:04
【问题描述】:

在实现角度材料表时出现以下错误。

错误:

类型“ListComponent”上不存在属性“tpl”。

我在下面解释我的代码。

<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>

我在这里使用[cdkDetailRowTpl]="tpl",而这里的错误来了。我需要一些帮助来解决这个错误。

【问题讨论】:

  • tpl 应该在你的组件中声明
  • 你有没有在list组件中声明过tpl变量
  • @HitechHitesh:不,我没有在我的 list.componet.ts 中声明。
  • 声明它并为其设置一个值,以便您的cdk可以获取值

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


【解决方案1】:

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

列表组件:

export class ListComponent implements OnInit {
  tpl: any;

  constructor() { }

  ngOnInit() {
  }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    • 2021-10-22
    • 2021-12-01
    • 2018-09-27
    相关资源
    最近更新 更多