diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/http-error-wrapper/http-error-wrapper.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/http-error-wrapper/http-error-wrapper.component.ts index 71566ff76c..618952b11a 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/http-error-wrapper/http-error-wrapper.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/http-error-wrapper/http-error-wrapper.component.ts @@ -13,11 +13,11 @@ import { OnDestroy, } from '@angular/core'; import { DOCUMENT } from '@angular/common'; +import { Router } from '@angular/router'; import { fromEvent, Subject } from 'rxjs'; import { debounceTime, filter } from 'rxjs/operators'; import { LocalizationParam, SubscriptionService } from '@abp/ng.core'; import { ErrorScreenErrorCodes } from '../../models'; -import { Router } from '@angular/router'; @Component({ selector: 'abp-http-error-wrapper', @@ -61,19 +61,21 @@ export class HttpErrorWrapperComponent implements OnInit, AfterViewInit, OnDestr } ngOnInit(): void { - this.backgroundColor = - this.window.getComputedStyle(this.document.body)?.getPropertyValue('background-color') || - '#fff'; + const computedStyle = this.window.getComputedStyle(this.document.body); + const backgroundColor = computedStyle?.getPropertyValue('background-color'); + this.backgroundColor = backgroundColor || '#fff'; } ngAfterViewInit(): void { if (this.customComponent) { - const customComponentRef = this.cfRes - .resolveComponentFactory(this.customComponent) - .create(this.injector); + const compFactory = this.cfRes.resolveComponentFactory(this.customComponent); + const customComponentRef = compFactory.create(this.injector); + customComponentRef.instance.errorStatus = this.status; customComponentRef.instance.destroy$ = this.destroy$; + this.appRef.attachView(customComponentRef.hostView); + if (this.containerRef) { this.containerRef.nativeElement.appendChild( (customComponentRef.hostView as EmbeddedViewRef).rootNodes[0], @@ -90,7 +92,7 @@ export class HttpErrorWrapperComponent implements OnInit, AfterViewInit, OnDestr } goHome() { - this.router.navigate(['/']); + this.router.navigateByUrl('/'); this.destroy(); } diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/create-error-component.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/create-error-component.service.ts index 5a6f02aef9..f1d738ec12 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/create-error-component.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/create-error-component.service.ts @@ -2,7 +2,9 @@ import { ApplicationRef, ComponentFactoryResolver, ComponentRef, + createComponent, EmbeddedViewRef, + EnvironmentInjector, inject, Injectable, Injector, @@ -24,6 +26,7 @@ export class CreateErrorComponentService { protected readonly cfRes = inject(ComponentFactoryResolver); protected readonly routerEvents = inject(RouterEvents); protected readonly injector = inject(Injector); + protected readonly envInjector = inject(EnvironmentInjector); protected readonly httpErrorConfig = inject(HTTP_ERROR_CONFIG); componentRef: ComponentRef | null = null; @@ -65,9 +68,9 @@ export class CreateErrorComponentService { const hostElement = this.getErrorHostElement(); const host = renderer.selectRootElement(hostElement, true); - this.componentRef = this.cfRes - .resolveComponentFactory(HttpErrorWrapperComponent) - .create(this.injector); + this.componentRef = createComponent(HttpErrorWrapperComponent, { + environmentInjector: this.envInjector, + }); for (const key in instance) { /* istanbul ignore else */ @@ -91,6 +94,7 @@ export class CreateErrorComponentService { const destroy$ = new Subject(); this.componentRef.instance.destroy$ = destroy$; + destroy$.subscribe(() => { this.componentRef?.destroy(); this.componentRef = null;