In my application, I've created a reusable modal popup component that takes a string as input and dynamically loads other components based on that input. This approach allows me to use the same modal popup component for multiple modals in the app instead of writing separate code for each one. However, I have encountered an issue where I'm using a large if/else statement to determine which component to load based on the string input:
if (this.data.component == "ContactStaffComponent")
componentFactory = this.componentFactoryResolver.resolveComponentFactory(ContactStaffComponent);
else if (this.data.component == "DocketComponent")
componentFactory = this.componentFactoryResolver.resolveComponentFactory(DocketComponent);
else if (this.data.component == "FilingComponent")
componentFactory = this.componentFactoryResolver.resolveComponentFactory(FilingComponent);
else if (this.data.component == "ServiceListRecordComponent")
componentFactory = this.componentFactoryResolver.resolveComponentFactory(ServiceListRecordComponent);
else { }
I am wondering if there is a way to convert the string into a type, similar to .NET reflection?