import { AfterContentChecked , Directive , ElementRef , TemplateRef , ViewContainerRef } from '@angular/core' ; @ Directive ( { selector : '[fuseIfOnDom]' } ) export class FuseIfOnDomDirective implements AfterContentChecked { isCreated : boolean ; param { ElementRef } _elementRef param { TemplateRef < any > } _templateRef param { ViewContainerRef } _viewContainerRef constructor ( private _elementRef , private _templateRef , private _viewContainerRef ) { this . isCreated = false ; } /**
     * After content checked
     */ ngAfterContentChecked ( ) { if ( document . body . contains ( this . _elementRef . nativeElement ) && ! this . isCreated ) { setTimeout ( ( ) => { this . _viewContainerRef . createEmbeddedView ( this . _templateRef ) ; } , 300 ) ; this . isCreated = true ; } else if ( this . isCreated && ! document . body . contains ( this . _elementRef . nativeElement ) ) { this . _viewContainerRef . clear ( ) ; this . isCreated = false ; } } }