I'm writing an app that lists some users and displays an information page when a user is clicked. The users are of different types (about 20 types) and the details page differs for each user type in layout and functionality.
I have a main DetailsComponent and 20 specific components (Type1DetailsComponent, Type2DetailsComponent, etc.) that must be displayed inside the main DetailsComponent.
I thought of two ways to implement this:
NgSwitch in the DetailsComponent to choose the specific componentComponentFactoryResolver and ViewContainerRef to create the specific component needed and display it inside DetailsComponent
The first method requires that all SpecificDetailsComponents be listed in the NgSwitch, reducing scalability.
The second method seems better, but it has a few drawbacks:
Is there anything I can do to improve the second method?
Are there any better methods of achieving the goal?
The target element does get replaced I believe, but either way it's just one errant element if it doesn't. The CFR is going to be ~50% faster even if the components are complicated I think.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With