11
2- import { ApplicationRef , ComponentFactoryResolver , Injectable , Injector } from '@angular/core' ;
2+ import { ApplicationRef , createComponent , EnvironmentInjector , Injectable } from '@angular/core' ;
33import { NgElement , WithProperties } from '@angular/elements' ;
44import { PopupComponent } from './popup.component' ;
55
66
77@Injectable ( )
88export class PopupService {
9- constructor ( private injector : Injector ,
10- private applicationRef : ApplicationRef ,
11- private componentFactoryResolver : ComponentFactoryResolver ) { }
9+ constructor ( private injector : EnvironmentInjector ,
10+ private applicationRef : ApplicationRef ) { }
1211
1312 // Previous dynamic-loading method required you to set up infrastructure
1413 // before adding the popup to the DOM.
@@ -17,8 +16,7 @@ export class PopupService {
1716 const popup = document . createElement ( 'popup-component' ) ;
1817
1918 // Create the component and wire it up with the element
20- const factory = this . componentFactoryResolver . resolveComponentFactory ( PopupComponent ) ;
21- const popupComponentRef = factory . create ( this . injector , [ ] , popup ) ;
19+ const popupComponentRef = createComponent ( PopupComponent , { environmentInjector : this . injector , hostElement : popup } ) ;
2220
2321 // Attach to the view so that the change detector knows to run
2422 this . applicationRef . attachView ( popupComponentRef . hostView ) ;
0 commit comments