{"record":{"id":"b4fdd2b9b41f30de","repo":"angular/components","slug":"text-column-could-not-find-a-parent-table-for-regi","errorCode":null,"errorMessage":"Text column could not find a parent table for registration.","messagePattern":"Text column could not find a parent table for registration\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cdk/table/text-column.ts","lineNumber":138,"sourceCode":"\n    if (this.headerText === undefined) {\n      this.headerText = this._createDefaultHeaderText();\n    }\n\n    if (!this.dataAccessor) {\n      this.dataAccessor =\n        this._options.defaultDataAccessor || ((data: T, name: string) => (data as any)[name]);\n    }\n\n    if (this._table) {\n      // Provide the cell and headerCell directly to the table with the static `ViewChild` query,\n      // since the columnDef will not pick up its content by the time the table finishes checking\n      // its content and initializing the rows.\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 getTableTextColumnMissingParentTableError();\n    }\n  }\n\n  ngOnDestroy() {\n    if (this._table) {\n      this._table.removeColumnDef(this.columnDef);\n    }\n  }\n\n  /**\n   * Creates a default header text. Use the options' header text transformation function if one\n   * has been provided. Otherwise simply capitalize the column name.\n   */\n  _createDefaultHeaderText() {\n    const name = this.name;\n\n    if (!name && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n      throw getTableTextColumnMissingNameError();","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/table/text-column.ts#L120-L156","documentation":"MatTextColumn must be declared inside a mat-table because ngOnInit injects the parent table via MAT_TABLE and registers its column def with it. When no parent table is found (injection or @ContentChild lookup failed) and dev mode is on, the component throws.","triggerScenarios":"TextColumn.ngOnInit: this._table is null/undefined when it tries this._table.addColumnDef(this.columnDef) — e.g. <mat-text-column> placed outside <mat-table>, or inside a component that isn't projecting it into the table.","commonSituations":"Placing mat-text-column in a sibling container rather than directly inside mat-table; using MatTextColumn without importing MatTableModule so the table provider is missing; wrapping the column in a custom component without forwarding the table injection.","solutions":["Move the <mat-text-column> element directly inside <table mat-table>...</table>","Ensure MatTableModule (or MatModule) is imported so the MAT_TABLE provider exists","If wrapping in a custom component, re-provide/inject MAT_TABLE and pass it down via the `table` input","Check that the table is a real mat-table (not plain table without the directive)"],"exampleFix":"// before\n<div class=\"wrapper\"><mat-text-column name=\"score\"></mat-text-column></div>\n<table mat-table [dataSource]=data> ... </table>\n// after\n<table mat-table [dataSource]=data>\n  <mat-text-column name=\"score\"></mat-text-column>\n  ...\n</table>","handlingStrategy":"validation","validationCode":"const table = hostEl.closest('table[mat-table]');\nif (!table) throw new Error('mat-text-column must be placed inside a mat-table');","typeGuard":"function isInsideMatTable(el: Element): boolean {\n  return !!el.closest('table[mat-table]');\n}","tryCatchPattern":"try {\n  this.cdr.detectChanges();\n} catch (e) {\n  if (/could not find a parent table/.test(e.message)) {\n    console.error('Move <mat-text-column> inside <table mat-table>.');\n  }\n}","preventionTips":["Place mat-text-column directly inside mat-table","Import MatTableModule so MAT_TABLE is provided","Re-inject/provide MAT_TABLE when wrapping columns in custom components"],"tags":["angular","material","text-column","missing-parent"],"backgroundTag":"missing-parent-table","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}