Skip to content

Commit 0ba8071

Browse files
committedAug 14, 2023
fix(material/table): resolve local compilation issues (#27640)
The Material table had a few places where it was importing a component's template as a string. This is incompatible with the upcoming local compilation mode in the compiler. These changes inline the templates instead. (cherry picked from commit 3f35b12)
1 parent 69652b0 commit 0ba8071

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed
 

‎src/material/table/row.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {
10-
CDK_ROW_TEMPLATE,
1110
CdkFooterRow,
1211
CdkFooterRowDef,
1312
CdkHeaderRow,
@@ -18,6 +17,9 @@ import {
1817
} from '@angular/cdk/table';
1918
import {ChangeDetectionStrategy, Component, Directive, ViewEncapsulation} from '@angular/core';
2019

20+
// We can't reuse `CDK_ROW_TEMPLATE` because it's incompatible with local compilation mode.
21+
const ROW_TEMPLATE = `<ng-container cdkCellOutlet></ng-container>`;
22+
2123
/**
2224
* Header row definition for the mat-table.
2325
* Captures the header row's template and other header properties such as the columns to display.
@@ -55,7 +57,7 @@ export class MatRowDef<T> extends CdkRowDef<T> {}
5557
/** Header template container that contains the cell outlet. Adds the right class and role. */
5658
@Component({
5759
selector: 'mat-header-row, tr[mat-header-row]',
58-
template: CDK_ROW_TEMPLATE,
60+
template: ROW_TEMPLATE,
5961
host: {
6062
'class': 'mat-mdc-header-row mdc-data-table__header-row',
6163
'role': 'row',
@@ -72,7 +74,7 @@ export class MatHeaderRow extends CdkHeaderRow {}
7274
/** Footer template container that contains the cell outlet. Adds the right class and role. */
7375
@Component({
7476
selector: 'mat-footer-row, tr[mat-footer-row]',
75-
template: CDK_ROW_TEMPLATE,
77+
template: ROW_TEMPLATE,
7678
host: {
7779
'class': 'mat-mdc-footer-row mdc-data-table__row',
7880
'role': 'row',
@@ -89,7 +91,7 @@ export class MatFooterRow extends CdkFooterRow {}
8991
/** Data row template container that contains the cell outlet. Adds the right class and role. */
9092
@Component({
9193
selector: 'mat-row, tr[mat-row]',
92-
template: CDK_ROW_TEMPLATE,
94+
template: ROW_TEMPLATE,
9395
host: {
9496
'class': 'mat-mdc-row mdc-data-table__row',
9597
'role': 'row',

‎src/material/table/table.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
ViewEncapsulation,
1515
} from '@angular/core';
1616
import {
17-
CDK_TABLE_TEMPLATE,
1817
CdkTable,
1918
_CoalescedStyleScheduler,
2019
_COALESCED_STYLE_SCHEDULER,
@@ -40,7 +39,17 @@ export class MatRecycleRows {}
4039
@Component({
4140
selector: 'mat-table, table[mat-table]',
4241
exportAs: 'matTable',
43-
template: CDK_TABLE_TEMPLATE,
42+
// Note that according to MDN, the `caption` element has to be projected as the **first**
43+
// element in the table. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption
44+
// We can't reuse `CDK_TABLE_TEMPLATE` because it's incompatible with local compilation mode.
45+
template: `
46+
<ng-content select="caption"></ng-content>
47+
<ng-content select="colgroup, col"></ng-content>
48+
<ng-container headerRowOutlet></ng-container>
49+
<ng-container rowOutlet></ng-container>
50+
<ng-container noDataRowOutlet></ng-container>
51+
<ng-container footerRowOutlet></ng-container>
52+
`,
4453
styleUrls: ['table.css'],
4554
host: {
4655
'class': 'mat-mdc-table mdc-data-table__table',

0 commit comments

Comments
 (0)
Please sign in to comment.