How can I dyamically reference a template?

Viewed 13

Basically, I am looking for a more elegant solution to this piece of code:

<ng-container *ngFor="let section of column.sections">
        <ng-container [ngSwitch]="section.type">
            <ng-container *ngSwitchCase="'text'">
                <ng-container *ngTemplateOutlet="text"></ng-container>
            </ng-container>
            <ng-container *ngSwitchCase="'title'">
                <ng-container *ngTemplateOutlet="title"></ng-container>
            </ng-container>
            <ng-container *ngSwitchCase="'links'">
                <ng-container *ngTemplateOutlet="links"></ng-container>
            </ng-container>
            <ng-container *ngSwitchCase="'selects'">
                <ng-container *ngTemplateOutlet="selects"></ng-container>
            </ng-container>
            <ng-container *ngSwitchCase="'images'">
                <ng-container *ngTemplateOutlet="images"></ng-container>
            </ng-container>
            <ng-container *ngSwitchDefault>
            </ng-container>
        </ng-container>
    </ng-container>

Sections contains an array of objects, where each section.type identifies what template it should use.

0 Answers
Related