1
1
import {
2
2
AfterContentChecked ,
3
3
Component ,
4
- ComponentFactoryResolver ,
5
4
ComponentRef ,
6
5
ContentChildren ,
7
6
ElementRef ,
@@ -13,7 +12,6 @@ import {
13
12
OnInit ,
14
13
QueryList ,
15
14
Renderer2 ,
16
- VERSION ,
17
15
ViewChild ,
18
16
ViewContainerRef
19
17
} from '@angular/core' ;
@@ -75,11 +73,10 @@ export class ToasterComponent implements OnDestroy, OnInit, AfterContentChecked
75
73
*/
76
74
@Input ( ) position : ( string | 'absolute' | 'fixed' | 'static' ) = 'absolute' ;
77
75
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 > ;
80
78
81
79
constructor (
82
- private componentFactoryResolver : ComponentFactoryResolver ,
83
80
private hostElement : ElementRef ,
84
81
private renderer : Renderer2 ,
85
82
private toasterService : ToasterService
@@ -99,7 +96,7 @@ export class ToasterComponent implements OnDestroy, OnInit, AfterContentChecked
99
96
'end-0' : this . placement . includes ( 'end' ) ,
100
97
'translate-middle-x' : this . placement . includes ( 'center' ) && ! this . placement . includes ( 'middle' ) ,
101
98
'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' )
103
100
} ;
104
101
}
105
102
@@ -115,15 +112,13 @@ export class ToasterComponent implements OnDestroy, OnInit, AfterContentChecked
115
112
this . toasts = this . contentToasts ;
116
113
}
117
114
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 ) ;
127
122
this . toastsDynamic . push ( componentRef ) ;
128
123
const index = this . toastsDynamic . indexOf ( componentRef ) ;
129
124
for ( const [ key , value ] of Object . entries ( props ) ) {
0 commit comments