11import {
22 AfterContentChecked ,
33 Component ,
4- ComponentFactoryResolver ,
54 ComponentRef ,
65 ContentChildren ,
76 ElementRef ,
@@ -13,7 +12,6 @@ import {
1312 OnInit ,
1413 QueryList ,
1514 Renderer2 ,
16- VERSION ,
1715 ViewChild ,
1816 ViewContainerRef
1917} from '@angular/core' ;
@@ -75,11 +73,10 @@ export class ToasterComponent implements OnDestroy, OnInit, AfterContentChecked
7573 */
7674 @Input ( ) position : ( string | 'absolute' | 'fixed' | 'static' ) = 'absolute' ;
7775
78- @ViewChild ( ToasterHostDirective , { static : true } ) toasterHost ! : ToasterHostDirective ;
79- @ContentChildren ( ToastComponent , { read : ViewContainerRef } ) contentToasts ! : QueryList < ViewContainerRef > ;
76+ @ViewChild ( ToasterHostDirective , { static : true } ) toasterHost ! : ToasterHostDirective ;
77+ @ContentChildren ( ToastComponent , { read : ViewContainerRef } ) contentToasts ! : QueryList < ViewContainerRef > ;
8078
8179 constructor (
82- private componentFactoryResolver : ComponentFactoryResolver ,
8380 private hostElement : ElementRef ,
8481 private renderer : Renderer2 ,
8582 private toasterService : ToasterService
@@ -99,7 +96,7 @@ export class ToasterComponent implements OnDestroy, OnInit, AfterContentChecked
9996 'end-0' : this . placement . includes ( 'end' ) ,
10097 'translate-middle-x' : this . placement . includes ( 'center' ) && ! this . placement . includes ( 'middle' ) ,
10198 'translate-middle-y' : this . placement . includes ( 'middle' ) && ! this . placement . includes ( 'center' ) ,
102- 'translate-middle' : this . placement . includes ( 'middle' ) && this . placement . includes ( 'center' ) ,
99+ 'translate-middle' : this . placement . includes ( 'middle' ) && this . placement . includes ( 'center' )
103100 } ;
104101 }
105102
@@ -115,15 +112,13 @@ export class ToasterComponent implements OnDestroy, OnInit, AfterContentChecked
115112 this . toasts = this . contentToasts ;
116113 }
117114
118- addToast ( toast : any , props : any , options ?: { index ?: number ; injector ?: Injector ; ngModuleRef ?: NgModuleRef < unknown > ; projectableNodes ?: Node [ ] [ ] ; } ) : ComponentRef < any > {
119- let componentRef : ComponentRef < any > ;
120- if ( parseInt ( VERSION . major ) < 13 ) {
121- const factory = this . componentFactoryResolver . resolveComponentFactory ( toast ) ;
122- componentRef = this . toasterHost . viewContainerRef . createComponent ( factory , options ?. index , options ?. injector , options ?. projectableNodes , options ?. ngModuleRef ) ;
123- } else {
124- // @ts -ignore
125- componentRef = this . toasterHost . viewContainerRef . createComponent ( toast , options ) ;
126- }
115+ addToast ( toast : any , props : any , options ?: {
116+ index ?: number ;
117+ injector ?: Injector ;
118+ ngModuleRef ?: NgModuleRef < unknown > ;
119+ projectableNodes ?: Node [ ] [ ] ;
120+ } ) : ComponentRef < any > {
121+ const componentRef : ComponentRef < any > = this . toasterHost . viewContainerRef . createComponent ( toast , options ) ;
127122 this . toastsDynamic . push ( componentRef ) ;
128123 const index = this . toastsDynamic . indexOf ( componentRef ) ;
129124 for ( const [ key , value ] of Object . entries ( props ) ) {
0 commit comments