@@ -21,7 +21,7 @@ import {
21
21
IterableChangeRecord ,
22
22
IterableDiffer ,
23
23
IterableDiffers ,
24
- NgIterable ,
24
+ NgIterable , NgZone ,
25
25
QueryList ,
26
26
Renderer2 ,
27
27
TrackByFunction ,
@@ -37,6 +37,7 @@ import {Subscription} from 'rxjs/Subscription';
37
37
import { Subject } from 'rxjs/Subject' ;
38
38
import { CdkCellDef , CdkColumnDef , CdkHeaderCellDef } from './cell' ;
39
39
import { getTableDuplicateColumnNameError , getTableUnknownColumnError } from './table-errors' ;
40
+ import { first } from '../rxjs/rx-operators' ;
40
41
41
42
/**
42
43
* 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 {
154
155
155
156
constructor ( private readonly _differs : IterableDiffers ,
156
157
private readonly _changeDetectorRef : ChangeDetectorRef ,
158
+ private readonly _ngZone : NgZone ,
157
159
elementRef : ElementRef ,
158
160
renderer : Renderer2 ,
159
161
@Attribute ( 'role' ) role : string ) {
@@ -167,6 +169,15 @@ export class CdkTable<T> implements CollectionViewer {
167
169
this . _dataDiffer = this . _differs . find ( [ ] ) . create ( this . _trackByFn ) ;
168
170
}
169
171
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
+
170
181
ngAfterContentInit ( ) {
171
182
// Initialize the column definitions map for easy lookup. Update the map when changed.
172
183
this . _cacheColumnDefinitionsByName ( ) ;
@@ -181,12 +192,6 @@ export class CdkTable<T> implements CollectionViewer {
181
192
this . _isViewInitialized = true ;
182
193
}
183
194
184
- ngDoCheck ( ) {
185
- if ( this . _isViewInitialized && this . dataSource && ! this . _renderChangeSubscription ) {
186
- this . _observeRenderChanges ( ) ;
187
- }
188
- }
189
-
190
195
ngOnDestroy ( ) {
191
196
this . _rowPlaceholder . viewContainer . clear ( ) ;
192
197
this . _headerRowPlaceholder . viewContainer . clear ( ) ;
0 commit comments