liveBook · Manning

matCellDef

As explained in Pro Angular 16

The matCellDef directive marks an Angular Material table template element as defining the contents of a data cell.

The matCellDef directive marks a td element as the template for an Angular Material table's data cells. Angular evaluates its expression for each item in the table data source, exposing the current item through a template variable such as item. section 2.5 section 28.2.2

Displaying a task property

Place matCellDef inside a column definition and bind the desired property: <td mat-cell *matCellDef="let item">{{ item.task }}</td>. For a counter rather than a data property, capture the supplied index: <td mat-cell *matCellDef="let i = index">{{ i + 1 }}</td>. The asterisk is significant because it applies Angular's concise template syntax.

The directive supports more than direct property display: its expression can format a value or combine multiple data-source properties. A price cell, for example, uses a currency pipe while retaining the current item as its context. section 28.2.2

Use matCellDef with the surrounding table configuration:

  • Pair the data-cell template with a header-cell template using matHeaderCellDef. section 2.5
  • Include the column name in the header and body row templates; columns are not displayed until selected there. section 28.2.2

How Pro Angular 16 covers it

How deep it goes
Explains per-item evaluation, implicit context, index access, formatting, and row selection while deferring full template-syntax details.
Examples
Uses task and counter cells in a to-do table plus a currency-formatted price cell in a product table.
What it assumes
Assumes basic Angular templates and data binding while clarifying the asterisk syntax and implicit row context.
What you can do after
Apply it via Angular Material to render direct, indexed, formatted, or composed values in table cells.
How it connects
Connects data binding with Angular Material tables, column definitions, row templates, template variables, and pipes.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.