@@ -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 [ ] | ReadonlyArray < 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
@@ -949,7 +962,9 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
949962 ] ;
950963
951964 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 ) ;
953968 element . appendChild ( section . outlet . elementRef . nativeElement ) ;
954969 this . _elementRef . nativeElement . appendChild ( element ) ;
955970 }
@@ -1001,7 +1016,9 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
10011016 */
10021017 private _setupStickyStyler ( ) {
10031018 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 ) ;
10051022 ( this . _dir ? this . _dir . change : observableOf < Direction > ( ) )
10061023 . pipe ( takeUntil ( this . _onDestroy ) )
10071024 . subscribe ( value => {
@@ -1012,6 +1029,6 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
10121029}
10131030
10141031/** 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 [ ] {
10161033 return queryList . toArray ( ) . concat ( Array . from ( set ) ) ;
10171034}
0 commit comments