import { ViewContainerRef , Injectable , Injector } from '@angular/core' ; import { OverlayRenderer , OverlayConfig } from '../models/tokens' ; import { DialogRefStack } from '../models/dialog-ref-stack' ; import { vcRefStore } from '../models/vc-ref-store' ; import { DialogRef } from '../models/dialog-ref' ; import { OverlayContext } from '../models/overlay-context' ; const _stack = new DialogRefStack < any > ( ) ; @ Injectable ( ) export class Overlay { get stackLength ( ) : number { return _stack . length ; } constructor ( private _modalRenderer , protected injector ) { } param dialogRef isTopMost ( dialogRef ) { return _stack . indexOf ( dialogRef ) === _stack . length - 1 ; } stackPosition ( dialogRef ) { return _stack . indexOf ( dialogRef ) ; } groupStackLength ( dialogRef ) { return _stack . groupLength ( _stack . groupOf ( dialogRef ) ) ; } closeAll ( result = null ) { _stack . closeAll ( result ) ; } param config param group open < T extends OverlayContext > ( config , group ? ) { let viewContainer = config . viewContainer , containers = [ ] ; if ( typeof viewContainer === 'string' ) { containers = vcRefStore . getVCRef ( viewContainer as string ) ; } else if ( Array . isArray ( viewContainer ) ) { containers = viewContainer as any ; } else if ( viewContainer ) { containers = [ viewContainer ] as any ; } else { containers = [ null ] ; } return containers . map ( vc => this . createOverlay ( config . renderer || this . _modalRenderer , vc , config , group ) ) ; } private createOverlay ( renderer , vcRef , config , group ) { if ( config . context ) { config . context . normalize ( ) ; } if ( ! config . injector ) { config . injector = this . injector ; } let dialog = new DialogRef < any > ( this , config . context || { } ) ; dialog . inElement = config . context && ! ! config . context . inElement ; let cmpRef = renderer . render ( dialog , vcRef , config . injector ) ; Object . defineProperty ( dialog , 'overlayRef' , { value : cmpRef } ) ; _stack . pushManaged ( dialog , group ) ; return dialog ; } }