From ca96318427be3b734637fc46d2cca90c376e4bd1 Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Thu, 24 Dec 2020 17:52:44 +0300 Subject: [PATCH] inject ApplicationRef at runtime in ErrorHandler --- .../theme-shared/src/lib/handlers/error.handler.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts b/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts index 46652f8b25..97f9533cf7 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts @@ -74,7 +74,6 @@ export class ErrorHandler { private actions: Actions, private router: Router, private confirmationService: ConfirmationService, - private appRef: ApplicationRef, private cfRes: ComponentFactoryResolver, private rendererFactory: RendererFactory2, private injector: Injector, @@ -281,14 +280,16 @@ export class ErrorHandler { } this.componentRef.instance.hideCloseIcon = this.httpErrorConfig.errorScreen.hideCloseIcon; + const appRef = this.injector.get(ApplicationRef); + if (this.canCreateCustomError(instance.status as ErrorScreenErrorCodes)) { this.componentRef.instance.cfRes = this.cfRes; - this.componentRef.instance.appRef = this.appRef; + this.componentRef.instance.appRef = appRef; this.componentRef.instance.injector = this.injector; this.componentRef.instance.customComponent = this.httpErrorConfig.errorScreen.component; } - this.appRef.attachView(this.componentRef.hostView); + appRef.attachView(this.componentRef.hostView); renderer.appendChild(host, (this.componentRef.hostView as EmbeddedViewRef).rootNodes[0]); const destroy$ = new Subject();