Skip to content

Commit 43e5f7b

Browse files
130715: Added try catch to catch an errors while resolving the lazyloaded component & renamed interface
1 parent d83c030 commit 43e5f7b

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/app/shared/abstract-component-loader/abstract-component-loader.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ export abstract class AbstractComponentLoaderComponent<T> implements OnInit, OnC
108108
* Creates the component and connects the @Input() & @Output() from the ThemedComponent to its child Component.
109109
*/
110110
public async instantiateComponent(): Promise<void> {
111-
const component: GenericConstructor<T> = await this.getComponent();
111+
let component: GenericConstructor<T>;
112+
try {
113+
component = await this.getComponent();
114+
} catch (error) {
115+
console.error('Failed to retrieve the component', error);
116+
return;
117+
}
112118

113119
const viewContainerRef: ViewContainerRef = this.componentViewContainerRef;
114120
viewContainerRef.clear();

src/app/shared/menu/menu-section/abstract-menu-section.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { MenuItemModel } from '../menu-item/models/menu-item.model';
3636
import { MenuItemType } from '../menu-item-type.model';
3737
import { MenuSection } from '../menu-section.model';
3838

39-
export interface MenuSectionDTO {
39+
export interface MenuSectionComponentDTO {
4040
injector: Injector;
4141
component: GenericConstructor<Component>;
4242
}
@@ -80,7 +80,7 @@ export abstract class AbstractMenuSectionComponent implements OnInit, OnChanges,
8080
/**
8181
* Map of components and injectors for each dynamically rendered menu section
8282
*/
83-
sectionMap: WritableSignal<Map<string, MenuSectionDTO>> = signal(new Map<string, MenuSectionDTO>());
83+
sectionMap: WritableSignal<Map<string, MenuSectionComponentDTO>> = signal(new Map<string, MenuSectionComponentDTO>());
8484

8585
/**
8686
* Array to track all subscriptions and unsubscribe them onDestroy
@@ -187,7 +187,7 @@ export abstract class AbstractMenuSectionComponent implements OnInit, OnChanges,
187187
* Update the sectionMap
188188
*/
189189
private updateSectionMap(id: string, injector: Injector, component: GenericConstructor<Component>) {
190-
this.sectionMap.update((sectionMap: Map<string, MenuSectionDTO>) => new Map(sectionMap.set(id, {
190+
this.sectionMap.update((sectionMap: Map<string, MenuSectionComponentDTO>) => new Map(sectionMap.set(id, {
191191
injector,
192192
component,
193193
})));

0 commit comments

Comments
 (0)