In my current project, we have a need for a scalable solution which will allow us to choose between multiple concrete component implementations based on server-side configuration. Without going into too much business detail, we might have multiple registration forms (RegistrationComponentA, RegistrationComponentB, RegistrationComponentC). The client is told by the server which implementation we should use.
At the moment our code might look something like this:
<registration-a [someProp]="serverValue" *ngIf="serverSays == 'a'"></registration-a>
<registration-b [someProp]="serverValue" *ngIf="serverSays == 'b'"></registration-b>
<registration-c [someProp]="serverValue" *ngIf="serverSays == 'c'"></registration-c>
Eventually, we may have 100 concrete implementations, and we want to do something more generic to avoid a template with 100 lines of *ngIf.
I would like to do something where I can just choose which component to render in the parent component itself, but from what I've been reading, using things like ComponentFactory solutions mess with change detection and require manual cleanup on destruction.
In AngularJS, I could manipulate the template and compile it on the fly and it would work fine, but with AoT, there is no compiler in the browser. (Thanks estus for pointing out that this was incorrect).
Is there an elegant way to handle this without having to manually handle change detection and lifecycle?