license import { Directive , TemplateRef , ComponentFactoryResolver , ApplicationRef , Injector , ViewContainerRef , Inject , OnDestroy , } from '@angular/core' ; import { TemplatePortal , DomPortalOutlet } from '@angular/cdk/portal' ; import { DOCUMENT } from '@angular/common' ; import { Subject } from 'rxjs' ; /**
 * Menu content that will be rendered lazily once the menu is opened.
 */ @ Directive ( { selector : 'ng-template[matMenuContent]' } ) export class MatMenuContent implements OnDestroy { private _portal : TemplatePortal < any > ; private _outlet : DomPortalOutlet ; /** Emits when the menu content has been attached. */ _attached = new Subject < void > ( ) ; constructor ( private _template , private _componentFactoryResolver , private _appRef , private _injector , private _viewContainerRef , @ Inject ( DOCUMENT ) private _document ) { } docs-private attach ( context = { } ) { if ( ! this . _portal ) { this . _portal = new TemplatePortal ( this . _template , this . _viewContainerRef ) ; } this . detach ( ) ; if ( ! this . _outlet ) { this . _outlet = new DomPortalOutlet ( this . _document . createElement ( 'div' ) , this . _componentFactoryResolver , this . _appRef , this . _injector ) ; } const element = this . _template . elementRef . nativeElement ; element . parentNode ! . insertBefore ( this . _outlet . outletElement , element ) ; this . _portal . attach ( this . _outlet , context ) ; this . _attached . next ( ) ; } docs-private detach ( ) { if ( this . _portal . isAttached ) { this . _portal . detach ( ) ; } } ngOnDestroy ( ) { if ( this . _outlet ) { this . _outlet . dispose ( ) ; } } }