{"record":{"id":"3ec67cdc8aae2d48","repo":"angular/components","slug":"matselectioncolumn-missing-parent-table","errorCode":null,"errorMessage":"MatSelectionColumn: missing parent table","messagePattern":"MatSelectionColumn: missing parent table","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material-experimental/selection/selection-column.ts","lineNumber":106,"sourceCode":"\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  }\n\n  private _syncColumnDefName() {\n    if (this._columnDef) {\n      this._columnDef.name = this._name;\n    }\n  }\n}\n","sourceCodeStart":88,"sourceCodeEnd":122,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material-experimental/selection/selection-column.ts#L88-L122","documentation":"MatSelectionColumn must register its column definition with a parent table via _table.addColumnDef. In dev mode, when the parent table reference is missing (the column is not inside the expected table element), ngOnInit throws this error. Without registration the column's cells would never render, so the library fails fast.","triggerScenarios":"Using `<mat-selection-column>` outside any parent table that implements addColumnDef/removeColumnDef — e.g. inside a plain `<table>` or standalone in a component template — so `this._table` is null in ngOnInit while ngDevMode is enabled.","commonSituations":"Rendering the column in a component that isn't inside the selection table; conditionally restructuring templates so the column's parent changes; migration to a different table wrapper that doesn't provide the table token.","solutions":["Wrap the selection column in the correct parent table element (mat-selection-table or equivalent) that injects/registers column defs.","Check that the column directive's parent selector actually matches your table (attribute/element selectors must line up).","Fix template structure after refactors — the column must be a direct descendant of the table providing the token.","Ensure the required experimental module is imported so the parent table directive is active."],"exampleFix":"// before\n<div class=\"my-table\">\n  <th mat-selection-column>Select</th>\n</div>\n\n// after\n<mat-selection-table>\n  <th mat-selection-column>Select</th>\n</mat-selection-table>","handlingStrategy":"type-guard","validationCode":"// Guard before placing the column in dynamic templates:\nconst tableEl = hostEl.nativeElement.closest('mat-selection-table');\nif (!tableEl) throw new Error('mat-selection-column must be inside a selection table');","typeGuard":"function hasSelectionTableParent(el: HTMLElement): boolean {\n  return el.closest('mat-selection-table') !== null;\n}","tryCatchPattern":"// Structural dev-mode error; resolve at template level, catch only for reporting:\ntry {\n  this.viewContainerRef.createComponent(SelectionColumnComponent);\n} catch (e) {\n  if (String(e.message).includes('missing parent table')) {\n    console.error('Selection column requires a parent table');\n  } else throw e;\n}","preventionTips":["Never render mat-selection-column outside its parent table, including with ngIf/structural directives that move it.","Re-check template nesting after refactors and migrations.","Test column rendering in dev mode where this guard is active.","Ensure the parent table directive's selector matches your actual markup."],"tags":["angular-material","template-structure","missing-parent","column-definition","ngdevmode"],"backgroundTag":"missing-parent-provider","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}