Skip to content

Commit 5042e08

Browse files
edusperoniZdravko
authored and
Zdravko
committed
Migrate from ReflectiveInjector (deprecated) to StaticInjector (#1868)
* chore: migrate to StaticInjector * chore: replace parentInjector in detached-loader
1 parent 1f56855 commit 5042e08

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

nativescript-angular/common/detached-loader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class DetachedLoader { // tslint:disable-line:component-class-suffix
2929
private loadInLocation(componentType: Type<any>): Promise<ComponentRef<any>> {
3030
const factory = this.resolver.resolveComponentFactory(componentType);
3131
const componentRef = this.containerRef.createComponent(
32-
factory, this.containerRef.length, this.containerRef.parentInjector);
32+
factory, this.containerRef.length, this.containerRef.injector);
3333

3434
// Component is created, built may not be checked if we are loading
3535
// inside component with OnPush CD strategy. Mark us for check to be sure CD will reach us.
@@ -52,6 +52,6 @@ export class DetachedLoader { // tslint:disable-line:component-class-suffix
5252

5353
public loadWithFactory<T>(factory: ComponentFactory<T>): ComponentRef<T> {
5454
return this.containerRef.createComponent(factory,
55-
this.containerRef.length, this.containerRef.parentInjector, null);
55+
this.containerRef.length, this.containerRef.injector, null);
5656
}
5757
}

nativescript-angular/directives/dialogs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
ComponentRef,
44
Directive,
55
Injectable,
6+
Injector,
67
NgModuleRef,
7-
ReflectiveInjector,
88
Type,
99
ViewContainerRef
1010
} from "@angular/core";
@@ -18,7 +18,7 @@ import { DetachedLoader } from "../common/detached-loader";
1818
import { PageFactory, PAGE_FACTORY } from "../platform-providers";
1919
import { once } from "../common/utils";
2020
import { topmost, Frame } from "tns-core-modules/ui/frame";
21-
import { ShowModalOptions } from "tns-core-modules/ui/core/view";
21+
import { ShowModalOptions } from "tns-core-modules/ui/core/view";
2222

2323
export type BaseShowModalOptions = Pick<ShowModalOptions, Exclude<keyof ShowModalOptions, "closeCallback" | "context">>;
2424

@@ -126,11 +126,11 @@ export class ModalDialogService {
126126
});
127127

128128
const modalParams = new ModalDialogParams(options.context, closeCallback);
129-
const providers = ReflectiveInjector.resolve([
130-
{ provide: ModalDialogParams, useValue: modalParams },
131-
]);
132129

133-
const childInjector = ReflectiveInjector.fromResolvedProviders(providers, options.containerRef.parentInjector);
130+
const childInjector = Injector.create({
131+
providers: [{ provide: ModalDialogParams, useValue: modalParams }],
132+
parent: options.containerRef.injector
133+
});
134134
const detachedFactory = options.resolver.resolveComponentFactory(DetachedLoader);
135135
detachedLoaderRef = options.containerRef.createComponent(detachedFactory, -1, childInjector, null);
136136
detachedLoaderRef.instance.loadComponent(options.type).then((compRef) => {

0 commit comments

Comments
 (0)