Browse Source

inject ApplicationRef at runtime in ErrorHandler

pull/6810/head
Arman Ozak 6 years ago
parent
commit
ca96318427
  1. 7
      npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts

7
npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts

@ -74,7 +74,6 @@ export class ErrorHandler {
private actions: Actions, private actions: Actions,
private router: Router, private router: Router,
private confirmationService: ConfirmationService, private confirmationService: ConfirmationService,
private appRef: ApplicationRef,
private cfRes: ComponentFactoryResolver, private cfRes: ComponentFactoryResolver,
private rendererFactory: RendererFactory2, private rendererFactory: RendererFactory2,
private injector: Injector, private injector: Injector,
@ -281,14 +280,16 @@ export class ErrorHandler {
} }
this.componentRef.instance.hideCloseIcon = this.httpErrorConfig.errorScreen.hideCloseIcon; this.componentRef.instance.hideCloseIcon = this.httpErrorConfig.errorScreen.hideCloseIcon;
const appRef = this.injector.get(ApplicationRef);
if (this.canCreateCustomError(instance.status as ErrorScreenErrorCodes)) { if (this.canCreateCustomError(instance.status as ErrorScreenErrorCodes)) {
this.componentRef.instance.cfRes = this.cfRes; 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.injector = this.injector;
this.componentRef.instance.customComponent = this.httpErrorConfig.errorScreen.component; 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<any>).rootNodes[0]); renderer.appendChild(host, (this.componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0]);
const destroy$ = new Subject<void>(); const destroy$ = new Subject<void>();

Loading…
Cancel
Save