kal93
kal93

Reputation: 572

ngTemplateOutlet doesn't seem to work with mat-cell

I'm trying to project content into a expanded row but no success so far. The same approach works everywhere else not sure why its not working with mat-table

<!-- Expanded Content Column - The detail row is made up of this one column that spans across all columns -->
  <ng-container matColumnDef="expandedDetail">
    <td mat-cell *matCellDef="let element" [attr.colspan]="columnsToDisplay.length">
      <div class="example-element-detail"
           [@detailExpand]="element == expandedElement ? 'expanded' : 'collapsed'">
        <div class="example-element-description">
          {{element.description}}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
          <span class="example-element-description-attribution"> -- Wikipedia 
<ng-container [ngTemplateOutlet]='rowDetail'></ng-container></span>
        </div>
      </div>
    </td>
  </ng-container>

And in the usage I tried

<demo-table 
[rowDetail]="rowDetailContent "
></demo-table>

<ng-template #rowDetailContent >
This is a passed template
</ng-template>

and this

<demo-table 
[rowDetail]="details "
></demo-table>

TS

@ViewChild('rowDetailContent') details :TemplateRef<any>;

None of them seem to work out.

Here's the Stackblitz

Upvotes: 0

Views: 628

Answers (1)

yurzui
yurzui

Reputation: 214017

Looking at your AppModule

entryComponents: [TableExpandableRowsExample,TableDemoComponent,RowDetailContent],
declarations: [TableDemoComponent,TableExpandableRowsExample,RowDetailContent],
bootstrap: [TableExpandableRowsExample,TableDemoComponent,RowDetailContent],

i suspect you don't know what is the purpose of these options.

Try removing TableDemoComponent and RowDetailContent from bootstrap option, so it should be:

bootstrap: [TableExpandableRowsExample]

Forked Stackblitz

Upvotes: 1

Related Questions