{"record":{"id":"d33b7638a35425a3","repo":"angular/components","slug":"matselectioncolumn-missing-matselection-in-the-pa","errorCode":null,"errorMessage":"MatSelectionColumn: missing MatSelection in the parent","messagePattern":"MatSelectionColumn: missing MatSelection in the parent","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material-experimental/selection/selection-column.ts","lineNumber":96,"sourceCode":"  @Input()\n  get name(): string {\n    return this._name;\n  }\n  set name(name: string) {\n    this._name = name;\n\n    this._syncColumnDefName();\n  }\n  private _name!: string;\n\n  @ViewChild(MatColumnDef, {static: true}) private readonly _columnDef!: MatColumnDef;\n  @ViewChild(MatCellDef, {static: true}) private readonly _cell!: MatCellDef;\n  @ViewChild(MatHeaderCellDef, {static: true})\n  private readonly _headerCell!: MatHeaderCellDef;\n\n  ngOnInit() {\n    if (!this.selection && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n      throw Error('MatSelectionColumn: missing MatSelection in the parent');\n    }\n\n    this._syncColumnDefName();\n\n    if (this._table) {\n      this._columnDef.cell = this._cell;\n      this._columnDef.headerCell = this._headerCell;\n      this._table.addColumnDef(this._columnDef);\n    } else if (typeof ngDevMode === 'undefined' || ngDevMode) {\n      throw Error('MatSelectionColumn: missing parent table');\n    }\n  }\n\n  ngOnDestroy() {\n    if (this._table) {\n      this._table.removeColumnDef(this._columnDef);\n    }\n  }","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material-experimental/selection/selection-column.ts#L78-L114","documentation":"MatSelectionColumn is a directive that expects to be used inside a <mat-selection-list>-style parent that provides the MatSelection injectable. In dev mode, if the MatSelection dependency is absent, the component throws this error during ngOnInit instead of failing later with an obscure null error. It is a structural/DI sanity check.","triggerScenarios":"Placing a `<mat-selection-column>` (or applying the selection-column directive) outside a component that provides MatSelection, so `this.selection` is undefined when ngOnInit runs; using the column with a plain `<table>` instead of the selection table wrapper.","commonSituations":"Copy-pasting the selection column markup into a regular MatTable without the experimental selection table; missing the required parent wrapper component after upgrading; forgetting to import the experimental selection module so the parent directive isn't matched.","solutions":["Place the selection column inside the proper parent element that provides MatSelection (the selection table/list container).","Import the experimental selection module (e.g. MatSelectionModule from @angular/material-experimental) so the parent directive is registered.","Verify the template structure matches the documented selection-table example (parent table + selection column).","If using a custom parent, provide MatSelection yourself via a directive/provider."],"exampleFix":"// before\n<table mat-table>\n  <th mat-selection-column>...</th>\n</table>\n\n// after\n<mat-selection-table> <!-- provides MatSelection -->\n  <th mat-selection-column>...</th>\n</mat-selection-table>","handlingStrategy":"type-guard","validationCode":"// In your component/directive, verify the structural context before rendering the column:\nif (!document.querySelector('mat-selection-table th mat-selection-column, table[mat-selection-table]')) {\n  console.warn('mat-selection-column used outside its required parent');\n}","typeGuard":"function isInsideSelectionColumnHost(el: HTMLElement): boolean {\n  return !!el.closest('mat-selection-table') && !!el.closest('th, td');\n}","tryCatchPattern":"// This is a dev-mode structural error; fix the template rather than catching it.\n// Use ErrorHandler only to log:\nexport class SelectionErrorHandler implements ErrorHandler {\n  handleError(e: any) {\n    if (!String(e?.message).includes('MatSelectionColumn')) throw e;\n    console.error('Template structure error:', e.message);\n  }\n}","preventionTips":["Always use the selection column inside the designated selection table parent.","Import the correct experimental selection module.","Follow the official selection-table template example when wiring up columns.","Keep dev mode enabled locally — ngDevMode guards catch these early."],"tags":["angular-material","dependency-injection","missing-provider","template-structure","ngdevmode"],"backgroundTag":"missing-parent-provider","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}