Skip to content

Commit e613a85

Browse files
committed
fix: destructible injector
1 parent 463b521 commit e613a85

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/angular/src/lib/legacy/router/page-router-outlet.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Attribute, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ComponentRef, Directive, Inject, InjectionToken, Injector, OnDestroy, EventEmitter, Output, Type, ViewContainerRef, ElementRef, InjectFlags, NgZone, EnvironmentInjector, inject } from '@angular/core';
1+
import { Attribute, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ComponentRef, Directive, Inject, InjectionToken, Injector, OnDestroy, EventEmitter, Output, Type, ViewContainerRef, ElementRef, InjectFlags, NgZone, EnvironmentInjector, inject, InjectOptions } from '@angular/core';
22
import { ActivatedRoute, ActivatedRouteSnapshot, ChildrenOutletContexts, Data, PRIMARY_OUTLET, Router, RouterOutletContract } from '@angular/router';
33

44
import { Frame, Page, NavigatedData, profile, NavigationEntry } from '@nativescript/core';
@@ -32,12 +32,20 @@ function isComponentFactoryResolver(item: any): item is ComponentFactoryResolver
3232
export class DestructibleInjector implements Injector {
3333
private refs = new Set<any>();
3434
constructor(private destructibleProviders: ProviderSet, private parent: Injector) {}
35-
get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T {
35+
get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectOptions | InjectFlags): T {
3636
const ref = this.parent.get(token, notFoundValue, flags);
37+
3738
// if we're skipping ourselves then it's not our responsibility to destroy
38-
if (!(flags & InjectFlags.SkipSelf) && this.destructibleProviders.has(token)) {
39-
this.refs.add(ref);
39+
if (typeof flags === 'number') {
40+
if (!(flags & InjectFlags.SkipSelf) && this.destructibleProviders.has(token)) {
41+
this.refs.add(ref);
42+
}
43+
} else {
44+
if (!flags?.skipSelf && this.destructibleProviders.has(token)) {
45+
this.refs.add(ref);
46+
}
4047
}
48+
4149
return ref;
4250
}
4351
destroy() {
@@ -71,7 +79,6 @@ export class PageRouterOutlet implements OnDestroy, RouterOutletContract {
7179
private isEmptyOutlet: boolean;
7280
private viewUtil: ViewUtil;
7381
private frame: Frame;
74-
private router = inject(Router);
7582

7683
attachEvents: EventEmitter<unknown> = new EventEmitter();
7784
detachEvents: EventEmitter<unknown> = new EventEmitter();

0 commit comments

Comments
 (0)