@@ -31,7 +31,9 @@ import {
31
31
ViewChild ,
32
32
ViewContainerRef ,
33
33
ViewEncapsulation ,
34
+ Inject ,
34
35
} from '@angular/core' ;
36
+ import { DOCUMENT } from '@angular/common' ;
35
37
import { BehaviorSubject , Observable , of as observableOf , Subject , Subscription } from 'rxjs' ;
36
38
import { takeUntil } from 'rxjs/operators' ;
37
39
import { CdkColumnDef } from './cell' ;
@@ -55,6 +57,7 @@ import {
55
57
import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
56
58
import { StickyStyler } from './sticky-styler' ;
57
59
import { Direction , Directionality } from '@angular/cdk/bidi' ;
60
+ import { Platform } from '@angular/cdk/platform' ;
58
61
59
62
/** Interface used to provide an outlet for rows to be inserted into. */
60
63
export interface RowOutlet {
@@ -148,6 +151,8 @@ export interface RenderRow<T> {
148
151
changeDetection : ChangeDetectionStrategy . OnPush ,
149
152
} )
150
153
export class CdkTable < T > implements AfterContentChecked , CollectionViewer , OnDestroy , OnInit {
154
+ private _document : Document ;
155
+
151
156
/** Latest data provided by the data source. */
152
157
protected _data : T [ ] | ReadonlyArray < T > ;
153
158
@@ -359,11 +364,19 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
359
364
protected readonly _changeDetectorRef : ChangeDetectorRef ,
360
365
protected readonly _elementRef : ElementRef ,
361
366
@Attribute ( 'role' ) role : string ,
362
- @Optional ( ) protected readonly _dir : Directionality ) {
367
+ @Optional ( ) protected readonly _dir : Directionality ,
368
+ /**
369
+ * @deprecated
370
+ * @breaking -change 8.0.0 `_document` and `_platform` to
371
+ * be made into a required parameters.
372
+ */
373
+ @Inject ( DOCUMENT ) _document ?: any ,
374
+ private _platform ?: Platform ) {
363
375
if ( ! role ) {
364
376
this . _elementRef . nativeElement . setAttribute ( 'role' , 'grid' ) ;
365
377
}
366
378
379
+ this . _document = _document ;
367
380
this . _isNativeHtmlTable = this . _elementRef . nativeElement . nodeName === 'TABLE' ;
368
381
}
369
382
@@ -949,7 +962,9 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
949
962
] ;
950
963
951
964
for ( const section of sections ) {
952
- const element = document . createElement ( section . tag ) ;
965
+ // @breaking -change 8.0.0 remove the `|| document` once the `_document` is a required param.
966
+ const documentRef = this . _document || document ;
967
+ const element = documentRef . createElement ( section . tag ) ;
953
968
element . appendChild ( section . outlet . elementRef . nativeElement ) ;
954
969
this . _elementRef . nativeElement . appendChild ( element ) ;
955
970
}
@@ -1001,7 +1016,9 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
1001
1016
*/
1002
1017
private _setupStickyStyler ( ) {
1003
1018
const direction : Direction = this . _dir ? this . _dir . value : 'ltr' ;
1004
- this . _stickyStyler = new StickyStyler ( this . _isNativeHtmlTable , this . stickyCssClass , direction ) ;
1019
+ this . _stickyStyler = new StickyStyler ( this . _isNativeHtmlTable ,
1020
+ // @breaking -change 8.0.0 remove the null check for `this._platform`.
1021
+ this . stickyCssClass , direction , this . _platform ? this . _platform . isBrowser : true ) ;
1005
1022
( this . _dir ? this . _dir . change : observableOf < Direction > ( ) )
1006
1023
. pipe ( takeUntil ( this . _onDestroy ) )
1007
1024
. subscribe ( value => {
@@ -1012,6 +1029,6 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
1012
1029
}
1013
1030
1014
1031
/** Utility function that gets a merged list of the entries in a QueryList and values of a Set. */
1015
- function mergeQueryListAndSet < T > ( queryList : QueryList < T > , set : Set < T > ) : T [ ] {
1032
+ function mergeQueryListAndSet < T > ( queryList : QueryList < T > , set : Set < T > ) : T [ ] {
1016
1033
return queryList . toArray ( ) . concat ( Array . from ( set ) ) ;
1017
1034
}
0 commit comments