Angular6 Material6错误:“只有一个默认行没有when谓词函数。”

Angular6 Material6错误:“只有一个默认行没有when谓词函数。”,angular6,angular-material-6,Angular6,Angular Material 6,我正在尝试使用中的可扩展行实现该表,但出现以下错误: 只有一个默认行没有when谓词函数 此错误来自以下事实:我有两个,结果是我缺少标记中的指令multiTemplateDataRows: 我也有同样的问题。我将@angular/cdk和@angular/material更新为6.4.7。一切都很好。当然,您还需要multiTemplateDataRows attr,如果when谓词中的函数未定义,也可能出现此错误。所以如果你有 如果hasChild未定义,则可能会出现该错误。请尝试以下操作:

我正在尝试使用中的可扩展行实现该表,但出现以下错误:

只有一个默认行没有when谓词函数


此错误来自以下事实:我有两个,结果是我缺少标记中的指令multiTemplateDataRows:


我也有同样的问题。我将@angular/cdk和@angular/material更新为6.4.7。一切都很好。当然,您还需要multiTemplateDataRows attr,如果when谓词中的函数未定义,也可能出现此错误。所以如果你有

如果hasChild未定义,则可能会出现该错误。

请尝试以下操作:

包装器-table.ts

从'@angular/cdk/collections'导入{SelectionModel}; 从“@angular/core”导入{AfterContentInit,Component,ContentChildren,Input,QueryList,TemplateRef,ViewChild}; 从“@angular/material/table”导入{MatColumnDef,MatHeaderRowDef,MatRowDef,MatTable,MatTableDataSource}; @组成部分{ 选择器:“ui包装表”, templateUrl:'./wrapper table.component.html', 样式URL:['./包装表.component.scss'] } 导出类包装器表实现AfterContentInit{ @ContentChildrenMathHeaderRowDef headerRowDefs:QueryList; @ContentChildrenMatrowDefRowDefs:QueryList; @ContentChildrenMatColumnDef columnDefs:QueryList; @ViewChildMatTable,{static:true}表:MatTable; @输入列:字符串[]; @输入数据源:MatTableDataSource; @输入contextTemplate:TemplateRef; @输入选择:SelectionModel; ngAfterContentInit{ this.columnDefs.forEachcolumnDef=>this.table.addColumnDefcolumnDef; this.rowDefs.forEachrowDef=>this.table.addRowDefrowDef; this.headerRowDefs.forEachheaderRowDef=>this.table.addheaderrowdef; } 我被选中了{ const numSelected=this.selection&&this.selection.selected.length | 0; const numRows=this.dataSource&&this.dataSource.data.length | 0; 返回numSelected==numRows; } 主开关{ 这个。我全部被选中了吗? 此.selection.clear: this.dataSource.data.forEachrow=>this.selection.selectrow; } checkboxLabelrow?:T:字符串{ 如果!划船{ 返回`${this.isAllSelected?'select':'deselect'}all`; } 返回`${this.selection.isSelectedrow?'deselect':'select'}行`; } } wrapper-table.html

{{element.id} 克里昂 {{element.created.toDate | date} 上下文 companys.component.ts

从'@angular/cdk/collections'导入{SelectionModel}; 从“@angular/core”导入{Component,OnDestroy,OnInit,ViewChild}; 从“@angular/material”导入{MatSort,MatTableDataSource}; 从'@apps waves/core'导入{CompanyModel,GetAllCompaniesUsecase}; 从'rxjs'导入{Subject}; 从“rxjs/operators”导入{takeUntil}; @组成部分{ 选择器:“波浪公司”, templateUrl:“./companys.component.html”, 样式URL:['./companys.component.scss'] } 导出类CompaniesComponent实现OnInit、OnDestroy{ displayedColumns:string[]=['select','name','companyType','created','context']; 数据源:MatTableDataSource; 选择:选择模型; @ViewChild'sort',{static:false}sort:MatSort; onDestroy=新主题; 建造师 私有GetAllCompanys:GetAllCompanyUseCase { } 恩戈尼特{ 此文件为.getAllCompanys.execute .pipetake直到这一天 .subscribecompanies=>{ this.dataSource=新MattableDataSource公司; this.selection=new SelectionModeltrue,[]; this.dataSource.sort=this.sort; } } onclick公司:CompanyModel{ console.logcompany; } 恩戈德斯特罗{ this.ondestory.next; 这是一个完整的; } } companies.html

<ui-wrapper-table
  [dataSource]="dataSource"
  [columns]="displayedColumns"
  [selection]="selection"
  matSort #sort="matSort"
  [contextTemplate]="rowContext">

  <!-- Custom column definition to be provided to the wrapper table. -->
  <ng-container matColumnDef="name">
    <th mat-header-cell *matHeaderCellDef> Name </th>
    <td mat-cell *matCellDef="let element"> {{element.name}} </td>
  </ng-container>

  <ng-container matColumnDef="companyType">
    <th mat-header-cell *matHeaderCellDef> Segmento </th>
    <td mat-cell *matCellDef="let element"> {{element.companyType}} </td>
  </ng-container>

  <!-- Custom row definitions to be provided to the wrapper table. -->
  <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns; "></tr>
</ui-wrapper-table>

<ng-template #rowContext let-element="row">
  <button type="button" mat-icon-button (click)="onClick(element)">
    <mat-icon>edit</mat-icon>
  </button>
</ng-template>

<pre>{{selection?.selected | json}}</pre>
它的工作非常酷

您的模板

hasChild = (_: number, node: FlatNode) => node.expandable;
您的组件应该有一个名为hasChild的方法


如果遇到未定义的“粘性”问题。检查matColumnDef?@BenTaliadoros asa中的列定义,您可以在上面的标签中看到,最后。谢谢,multiTemplateDataRows在没有更新的情况下无法工作。在得到公认的答案后,这确实帮助了我。非常感谢。
mat-tree-node(*matTreeNodeDef="let node;when: hasChild", matTreeNodePadding)
hasChild = (_: number, node: FlatNode) => node.expandable;