|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import { ComponentFactoryResolver, ComponentRef, EmbeddedViewRef, ApplicationRef, Injector, Renderer2, Optional } from '@angular/core'; |
| 9 | +import { ComponentFactoryResolver, ComponentRef, EmbeddedViewRef, ApplicationRef, Injector, Renderer2, Optional, createComponent } from '@angular/core'; |
10 | 10 | import { View } from '@nativescript/core';
|
11 | 11 | import { CommentNode } from '../../views/invisible-nodes';
|
12 | 12 | import { ViewUtil } from '../../view-util';
|
@@ -36,20 +36,24 @@ export class NativeScriptDomPortalOutlet extends BasePortalOutlet {
|
36 | 36 | * @returns Reference to the created component.
|
37 | 37 | */
|
38 | 38 | attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
|
39 |
| - const resolver = portal.componentFactoryResolver || this._componentFactoryResolver; |
40 |
| - const componentFactory = resolver.resolveComponentFactory(portal.component); |
41 | 39 | let componentRef: ComponentRef<T>;
|
42 | 40 |
|
43 | 41 | // If the portal specifies a ViewContainerRef, we will use that as the attachment point
|
44 | 42 | // for the component (in terms of Angular's component tree, not rendering).
|
45 | 43 | // When the ViewContainerRef is missing, we use the factory to create the component directly
|
46 | 44 | // and then manually attach the view to the application.
|
47 | 45 | if (portal.viewContainerRef) {
|
48 |
| - componentRef = portal.viewContainerRef.createComponent(componentFactory, portal.viewContainerRef.length, portal.injector || portal.viewContainerRef.injector); |
| 46 | + componentRef = portal.viewContainerRef.createComponent(portal.component, { |
| 47 | + index: portal.viewContainerRef.length, |
| 48 | + injector: portal.injector || portal.viewContainerRef.injector, |
| 49 | + }); |
49 | 50 |
|
50 | 51 | this.setDisposeFn(() => componentRef.destroy());
|
51 | 52 | } else {
|
52 |
| - componentRef = componentFactory.create(portal.injector || this._defaultInjector); |
| 53 | + componentRef = createComponent(portal.component, { |
| 54 | + elementInjector: portal.injector || this._defaultInjector || Injector.NULL, |
| 55 | + environmentInjector: this._appRef.injector, |
| 56 | + }); |
53 | 57 | this._appRef.attachView(componentRef.hostView);
|
54 | 58 | this.setDisposeFn(() => {
|
55 | 59 | this._appRef.detachView(componentRef.hostView);
|
|
0 commit comments