Skip to content

Commit 33d4dc6

Browse files
authored
fix: load pages in location instead of in appRef (#74)
1 parent a0fd7f5 commit 33d4dc6

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

packages/angular/src/lib/cdk/detached-loader.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ registerElement('DetachedContainer', () => ProxyViewContainer, {
1616
@Component({
1717
// eslint-disable-next-line @angular-eslint/component-selector
1818
selector: 'DetachedContainer',
19-
template: `<Placeholder #loader></Placeholder><ng-container #vc></ng-container><ng-content></ng-content>`,
19+
template: `<Placeholder #loader></Placeholder>
20+
<ng-container #vc></ng-container>
21+
<ng-content></ng-content>`,
2022
})
2123
// eslint-disable-next-line @angular-eslint/component-class-suffix
2224
export class DetachedLoader implements OnDestroy {
@@ -33,7 +35,7 @@ export class DetachedLoader implements OnDestroy {
3335
return new TemplatePortal(templateRef, this.vc, context);
3436
}
3537

36-
private loadInLocation(componentType: Type<any>): ComponentRef<any> {
38+
private loadInAppRef(componentType: Type<any>): ComponentRef<any> {
3739
const factory = this.resolver.resolveComponentFactory(componentType);
3840
const componentRef = factory.create(this.containerRef.injector);
3941
this.appRef.attachView(componentRef.hostView);
@@ -52,6 +54,10 @@ export class DetachedLoader implements OnDestroy {
5254
return componentRef;
5355
}
5456

57+
private loadInLocation(componentType: Type<any>): ComponentRef<any> {
58+
return this.vc.createComponent(componentType);
59+
}
60+
5561
public ngOnDestroy() {
5662
this.disposeFunctions.forEach((fn) => fn());
5763
}
@@ -65,14 +71,22 @@ export class DetachedLoader implements OnDestroy {
6571
*/
6672
public loadComponent(componentType: Type<any>): Promise<ComponentRef<any>> {
6773
Trace.write('DetachedLoader.loadComponent', 'detached-loader');
68-
return Promise.resolve(this.loadInLocation(componentType));
74+
return Promise.resolve(this.loadInAppRef(componentType));
6975
}
7076

7177
/**
7278
* @deprecated use Portals
7379
*/
7480
public loadComponentSync(componentType: Type<any>): ComponentRef<any> {
75-
Trace.write('DetachedLoader.loadComponent', 'detached-loader');
81+
Trace.write('DetachedLoader.loadComponentSync', 'detached-loader');
82+
return this.loadInAppRef(componentType);
83+
}
84+
85+
/**
86+
* @deprecated use Portals
87+
*/
88+
public loadComponentInLocation(componentType: Type<any>): ComponentRef<any> {
89+
Trace.write('DetachedLoader.loadComponentInLocation', 'detached-loader');
7690
return this.loadInLocation(componentType);
7791
}
7892

@@ -89,4 +103,11 @@ export class DetachedLoader implements OnDestroy {
89103
});
90104
return componentRef;
91105
}
106+
107+
/**
108+
* @deprecated use Portals
109+
*/
110+
public loadWithFactoryInLocation<T>(factory: ComponentFactory<T>): ComponentRef<T> {
111+
return this.vc.createComponent(factory);
112+
}
92113
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export class PageRouterOutlet implements OnDestroy, RouterOutletContract {
352352
loaderRef.onDestroy(() => childInjector.destroy());
353353
this.changeDetector.markForCheck();
354354

355-
this.activated = loaderRef.instance.loadWithFactory(factory);
355+
this.activated = loaderRef.instance.loadWithFactoryInLocation(factory);
356356
this.activated.changeDetectorRef.detectChanges();
357357
this.loadComponentInPage(page, this.activated, { activatedRoute });
358358

0 commit comments

Comments
 (0)