@@ -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
+ * @deletion -target 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
@@ -947,7 +960,9 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
947
960
] ;
948
961
949
962
for ( const section of sections ) {
950
- const element = document . createElement ( section . tag ) ;
963
+ // @deletion -target 8.0.0 remove the `|| document` once the `_document` is a required param.
964
+ const documentRef = this . _document || document ;
965
+ const element = documentRef . createElement ( section . tag ) ;
951
966
element . appendChild ( section . outlet . elementRef . nativeElement ) ;
952
967
this . _elementRef . nativeElement . appendChild ( element ) ;
953
968
}
@@ -999,7 +1014,9 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
999
1014
*/
1000
1015
private _setupStickyStyler ( ) {
1001
1016
const direction : Direction = this . _dir ? this . _dir . value : 'ltr' ;
1002
- this . _stickyStyler = new StickyStyler ( this . _isNativeHtmlTable , this . stickyCssClass , direction ) ;
1017
+ this . _stickyStyler = new StickyStyler ( this . _isNativeHtmlTable ,
1018
+ // @deletion -target 8.0.0 remove the null check for `this._platform`.
1019
+ this . stickyCssClass , direction , this . _platform ? this . _platform . isBrowser : true ) ;
1003
1020
( this . _dir ? this . _dir . change : observableOf < Direction > ( ) )
1004
1021
. pipe ( takeUntil ( this . _onDestroy ) )
1005
1022
. subscribe ( value => {
@@ -1010,6 +1027,6 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
1010
1027
}
1011
1028
1012
1029
/** Utility function that gets a merged list of the entries in a QueryList and values of a Set. */
1013
- function mergeQueryListAndSet < T > ( queryList : QueryList < T > , set : Set < T > ) : T [ ] {
1030
+ function mergeQueryListAndSet < T > ( queryList : QueryList < T > , set : Set < T > ) : T [ ] {
1014
1031
return queryList . toArray ( ) . concat ( Array . from ( set ) ) ;
1015
1032
}
0 commit comments