Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular6 Material6 Error: "There can only be one default row without a when predicate function."

I'm trying to implement the Table with expandable rows from https://material.angular.io/components/table/examples but I get this error:

There can only be one default row without a when predicate function.

This error comes from the fact that I have two <tr mat-row ..., both without a when predicate (as per example). If I remove one, then the error disappears.

From my own investigation I've found that this feature is new to Material. I upgraded to @angular/material@latest and @angular/cdk@latest and I still got the error.

Does anyone know what I have to do to implement the table as in the example from documentation? https://material.angular.io/components/table/examples

My versions:

Angular CLI: 6.0.8
Node: 8.11.2
OS: win32 x64
Angular: 6.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cdk                      6.3.1
@angular/cli                      6.0.8
@angular/flex-layout              6.0.0-beta.16
@angular/material                 6.3.1
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.2.0
typescript                        2.7.2
webpack                           4.8.3
like image 1000
GoTo Avatar asked Jun 29 '18 05:06

GoTo


2 Answers

It turns out I was missing directive multiTemplateDataRows from <table> tag:

<table mat-table [dataSource]="licenses" multiTemplateDataRows> 
like image 152
GoTo Avatar answered Sep 20 '22 10:09

GoTo


This error could also appear if the function in your when predicate is undefined. So if you have

<mat-tree-node *matTreeNodeDef="let node; when: hasChild">

and hasChild is undefined, you could get that error.

like image 23
adamdport Avatar answered Sep 20 '22 10:09

adamdport