import { INotyfStyle } from './inotyf-style' ; import { Injectable , Injector , ComponentFactoryResolver , EmbeddedViewRef , ApplicationRef , ComponentRef } from '@angular/core' ; @ Injectable ( ) export class DomService { constructor ( private componentFactoryResolver , private appRef , private injector ) { } createComponentRef ( component ) { const componentRef = this . componentFactoryResolver . resolveComponentFactory ( component ) . create ( this . injector ) ; this . appRef . attachView ( componentRef . hostView ) ; return componentRef ; } getDomElementFromComponentRef ( componentRef ) { return ( componentRef . hostView as EmbeddedViewRef < any > ) . rootNodes [ 0 ] as HTMLElement ; } addChild ( child , parent = document . body ) { parent . appendChild ( child ) ; } destroyRef ( componentRef , delay ) { setTimeout ( ( ) => { this . appRef . detachView ( componentRef . hostView ) ; componentRef . destroy ( ) ; } , delay ) ; } setDynamicStyles ( styles , componentRef ) { Object . keys ( styles ) . forEach ( cssRule => { let cssValue = styles [ cssRule ] ; componentRef . instance . renderer . setElementStyle ( componentRef . instance . elementRef . nativeElement , cssRule , cssValue ) ; } ) ; } }