@@ -31,7 +31,9 @@ import {
3131 ViewChild ,
3232 ViewContainerRef ,
3333 ViewEncapsulation ,
34+ Inject ,
3435} from '@angular/core' ;
36+ import { DOCUMENT } from '@angular/common' ;
3537import { BehaviorSubject , Observable , of as observableOf , Subject , Subscription } from 'rxjs' ;
3638import { takeUntil } from 'rxjs/operators' ;
3739import { CdkColumnDef } from './cell' ;
@@ -55,6 +57,7 @@ import {
5557import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
5658import { StickyStyler } from './sticky-styler' ;
5759import { Direction , Directionality } from '@angular/cdk/bidi' ;
60+ import { Platform } from '@angular/cdk/platform' ;
5861
5962/** Interface used to provide an outlet for rows to be inserted into. */
6063export interface RowOutlet {
@@ -148,6 +151,8 @@ export interface RenderRow<T> {
148151 changeDetection : ChangeDetectionStrategy . OnPush ,
149152} )
150153export class CdkTable < T > implements AfterContentChecked , CollectionViewer , OnDestroy , OnInit {
154+ private _document : Document ;
155+
151156 /** Latest data provided by the data source. */
152157 protected _data : T [ ] ;
153158
@@ -359,11 +364,19 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
359364 protected readonly _changeDetectorRef : ChangeDetectorRef ,
360365 protected readonly _elementRef : ElementRef ,
361366 @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 ) {
363375 if ( ! role ) {
364376 this . _elementRef . nativeElement . setAttribute ( 'role' , 'grid' ) ;
365377 }
366378
379+ this . _document = _document ;
367380 this . _isNativeHtmlTable = this . _elementRef . nativeElement . nodeName === 'TABLE' ;
368381 }
369382
@@ -947,7 +960,9 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
947960 ] ;
948961
949962 for ( const section of sections ) {
950- const element = document . createElement ( section . tag ) ;
963+ // @breaking -change 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 ) ;
951966 element . appendChild ( section . outlet . elementRef . nativeElement ) ;
952967 this . _elementRef . nativeElement . appendChild ( element ) ;
953968 }
@@ -999,7 +1014,9 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
9991014 */
10001015 private _setupStickyStyler ( ) {
10011016 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+ // @breaking -change 8.0.0 remove the null check for `this._platform`.
1019+ this . stickyCssClass , direction , this . _platform ? this . _platform . isBrowser : true ) ;
10031020 ( this . _dir ? this . _dir . change : observableOf < Direction > ( ) )
10041021 . pipe ( takeUntil ( this . _onDestroy ) )
10051022 . subscribe ( value => {
@@ -1010,6 +1027,6 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
10101027}
10111028
10121029/** 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 [ ] {
10141031 return queryList . toArray ( ) . concat ( Array . from ( set ) ) ;
10151032}
0 commit comments