license import { DOCUMENT } from '@angular/common' ; import { Inject , Injectable , OnDestroy } from '@angular/core' ; import { Platform , _isTestEnvironment } from '@angular/cdk/platform' ; /** Container inside which all overlays will render. */ @ Injectable ( { providedIn : 'root' } ) export class OverlayContainer implements OnDestroy { protected _containerElement : HTMLElement ; protected _document : Document ; constructor ( @ Inject ( DOCUMENT ) document , protected _platform ) { this . _document = document ; } ngOnDestroy ( ) { this . _containerElement ?. remove ( ) ; } returns getContainerElement ( ) { if ( ! this . _containerElement ) { this . _createContainer ( ) ; } return this . _containerElement ; } /**
     * Create the overlay container element, which is simply a div
     * with the 'cdk-overlay-container' class on the document body.
     */ protected _createContainer ( ) { const containerClass = 'cdk-overlay-container' ; if ( this . _platform . isBrowser || _isTestEnvironment ( ) ) { const oppositePlatformContainers = this . _document . querySelectorAll ( `.${ containerClass }[platform="server"], ` + `.${ containerClass }[platform="test"]` ) ; for ( let i = 0 ; i < oppositePlatformContainers . length ; i ++ ) { oppositePlatformContainers [ i ] . remove ( ) ; } } const container = this . _document . createElement ( 'div' ) ; container . classList . add ( containerClass ) ; if ( _isTestEnvironment ( ) ) { container . setAttribute ( 'platform' , 'test' ) ; } else if ( ! this . _platform . isBrowser ) { container . setAttribute ( 'platform' , 'server' ) ; } this . _document . body . appendChild ( container ) ; this . _containerElement = container ; } }