My idea is to modify component selector string with variable so that I could dynamically select template to display.
Unfortunately using simple "<app-{{selectedComponent}}></app-{{selectedComponent}}>"
inside *ngFor
loop do not work.
Is there any way to dynamically select component to display?
CodePudding user response:
You should use structural directive *ngIf
to display some element/component dynamically inside your .html
file.
An example would be:
<app-xyz-component *ngIf='someCase'><app-xyz-component>
If the expression is true
component will be rendered.
CodePudding user response:
As far as I know, it's not possible but you can use ngSwitch
or ngIf
or if you want to dynamically create components on the fly you can use Dynamic component loader follow this link Or this link