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

GoTo picture GoTo · Jun 29, 2018 · Viewed 22.1k times · Source

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

Answer

GoTo picture GoTo · Jun 29, 2018

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

<table mat-table [dataSource]="licenses" multiTemplateDataRows ...