Skip to content

Commit d596ec0

Browse files
JeanMecheatscott
authored andcommitted
docs: Update Popup.service example to remove ComponentFactoryResolver (#49638)
`ComponentFactoryResolver` has been deprecated and can be replaced by `createComponent()`. PR Close #49638
1 parent 06e74a5 commit d596ec0

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

aio/content/examples/elements/src/app/popup.service.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11

2-
import { ApplicationRef, ComponentFactoryResolver, Injectable, Injector } from '@angular/core';
2+
import { ApplicationRef, createComponent, EnvironmentInjector, Injectable } from '@angular/core';
33
import { NgElement, WithProperties } from '@angular/elements';
44
import { PopupComponent } from './popup.component';
55

66

77
@Injectable()
88
export 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

Comments
 (0)