import { NgIf } from '@angular/common' ; import { ChangeDetectorRef , Directive , ElementRef , Input , Renderer2 , RendererStyleFlags2 , TemplateRef , ViewContainerRef , ViewRef , } from '@angular/core' ; @ Directive ( { selector : '[ngxCacheIf]' , } ) export class NgxCacheIfDirective { @ Input ( ) set ngxCacheIf ( value ) { this . rendered = this . rendered || value ; this . ngIfDirective . ngIf = this . rendered ; setTimeout ( ( ) => { if ( this . rendered ) { if ( ! value ) { this . renderer . setStyle ( this . el . nativeElement . nextSibling , 'display' , 'none' , RendererStyleFlags2 . DashCase | RendererStyleFlags2 . Important ) ; } else { this . renderer . removeStyle ( this . el . nativeElement . nextSibling , 'display' ) ; } if ( ! ( this . cdr as ViewRef ) ?. destroyed ) { this . cdr . detectChanges ( ) ; } } } ) ; } private rendered : boolean ; private ngIfDirective : NgIf ; constructor ( private readonly el , private readonly renderer , private readonly templateRef , private readonly viewContainer , private readonly cdr ) { if ( ! this . ngIfDirective ) { this . ngIfDirective = new NgIf ( this . viewContainer , this . templateRef ) ; } } }