Skip to content

Commit 2498b7e

Browse files
committed
add comment about ngDoCheck()
1 parent 68919d6 commit 2498b7e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
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 & 1 deletion
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.
@@ -151,6 +152,7 @@ export class CdkTable<T> implements CollectionViewer {
151152

152153
constructor(private readonly _differs: IterableDiffers,
153154
private readonly _changeDetectorRef: ChangeDetectorRef,
155+
private readonly _ngZone: NgZone,
154156
elementRef: ElementRef,
155157
renderer: Renderer2,
156158
@Attribute('role') role: string) {
@@ -164,6 +166,15 @@ export class CdkTable<T> implements CollectionViewer {
164166
this._dataDiffer = this._differs.find([]).create(this._trackByFn);
165167
}
166168

169+
ngDoCheck() {
170+
// After the the content and view have been initialized and checked then we can connect
171+
// to the data source and render data rows. This cannot be done from within change detection,
172+
// so the table must wait until the next change detection cycle before rendering.
173+
if (this._isViewInitialized && this.dataSource && !this._renderChangeSubscription) {
174+
this._observeRenderChanges();
175+
}
176+
}
177+
167178
ngAfterContentInit() {
168179
this._cacheColumnDefinitionsByName();
169180
this._columnDefinitions.changes.subscribe(() => this._cacheColumnDefinitionsByName());

0 commit comments

Comments
 (0)