Skip to content

Commit c20f334

Browse files
committed
add comment about ngDoCheck()
1 parent 138e2b2 commit c20f334

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/cdk/table/table.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {CdkTableModule} from './index';
99
import {map} from 'rxjs/operator/map';
1010
import {getTableDuplicateColumnNameError, getTableUnknownColumnError} from './table-errors';
1111

12-
describe('CdkTable', () => {
12+
fdescribe('CdkTable', () => {
1313
let fixture: ComponentFixture<SimpleCdkTableApp>;
1414

1515
let component: SimpleCdkTableApp;

src/cdk/table/table.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
IterableChangeRecord,
2222
IterableDiffer,
2323
IterableDiffers,
24-
NgIterable,
24+
NgIterable, NgZone,
2525
QueryList,
2626
Renderer2,
2727
TrackByFunction,
@@ -37,6 +37,7 @@ import {Subscription} from 'rxjs/Subscription';
3737
import {Subject} from 'rxjs/Subject';
3838
import {CdkCellDef, CdkColumnDef, CdkHeaderCellDef} from './cell';
3939
import {getTableDuplicateColumnNameError, getTableUnknownColumnError} from './table-errors';
40+
import {first} from '../rxjs/rx-operators';
4041

4142
/**
4243
* Provides a handle for the table to grab the view container's ng-container to insert data rows.
@@ -154,6 +155,7 @@ export class CdkTable<T> implements CollectionViewer {
154155

155156
constructor(private readonly _differs: IterableDiffers,
156157
private readonly _changeDetectorRef: ChangeDetectorRef,
158+
private readonly _ngZone: NgZone,
157159
elementRef: ElementRef,
158160
renderer: Renderer2,
159161
@Attribute('role') role: string) {
@@ -167,6 +169,15 @@ export class CdkTable<T> implements CollectionViewer {
167169
this._dataDiffer = this._differs.find([]).create(this._trackByFn);
168170
}
169171

172+
ngDoCheck() {
173+
// After the the content and view have been initialized and checked then we can connect
174+
// to the data source and render data rows. This cannot be done from within change detection,
175+
// so the table must wait until the next change detection cycle before rendering.
176+
if (this._isViewInitialized && this.dataSource && !this._renderChangeSubscription) {
177+
this._observeRenderChanges();
178+
}
179+
}
180+
170181
ngAfterContentInit() {
171182
// Initialize the column definitions map for easy lookup. Update the map when changed.
172183
this._cacheColumnDefinitionsByName();
@@ -181,12 +192,6 @@ export class CdkTable<T> implements CollectionViewer {
181192
this._isViewInitialized = true;
182193
}
183194

184-
ngDoCheck() {
185-
if (this._isViewInitialized && this.dataSource && !this._renderChangeSubscription) {
186-
this._observeRenderChanges();
187-
}
188-
}
189-
190195
ngOnDestroy() {
191196
this._rowPlaceholder.viewContainer.clear();
192197
this._headerRowPlaceholder.viewContainer.clear();

0 commit comments

Comments
 (0)