11import {
22 ApplicationRef ,
33 ChangeDetectorRef ,
4- ComponentFactoryResolver ,
54 ComponentRef ,
5+ createComponent ,
66 Injectable ,
7- Injector ,
87 Type ,
98} from '@angular/core' ;
10- import { ComponentPortal , DomPortalOutlet } from '@angular/cdk/portal' ;
119import 'winbox' ;
1210
1311declare const WinBox : WinBox . WinBoxConstructor ;
@@ -25,12 +23,7 @@ export class WinboxService {
2523 private winBoxStack : WinBox [ ] = [ ] ;
2624 public isThereAWinBox = false ;
2725
28- constructor (
29- private componentFactoryResolver : ComponentFactoryResolver ,
30- private injector : Injector ,
31- private appRef : ApplicationRef
32- ) { }
33-
26+ constructor ( private appRef : ApplicationRef ) { }
3427 get numberOfWinBoxes ( ) : number {
3528 return this . winBoxStack . length ;
3629 }
@@ -41,18 +34,11 @@ export class WinboxService {
4134 ) : WinBoxContainer < ComponentInstance > {
4235 const winBox = new WinBox ( options ) ;
4336
44- const portalHost = new DomPortalOutlet (
45- winBox . body ,
46- this . componentFactoryResolver ,
47- this . appRef ,
48- this . injector
49- ) ;
50-
51- // Locate the component factory for the HeaderComponent
52- const portal = new ComponentPortal ( component ) ;
53-
54- // Attach portal to host
55- const componentRef = portalHost . attach ( portal ) ;
37+ const componentRef = createComponent ( component , {
38+ environmentInjector : this . appRef . injector ,
39+ hostElement : winBox . body ,
40+ } ) ;
41+ this . appRef . attachView ( componentRef . hostView ) ;
5642
5743 // estensione del metodo per permettere all'utente di passare
5844 // una funzione da invocare alla chiusura della winBox
0 commit comments