Difference between *ngIf vs [ngSwitch] in Angular 2+

Discussão em 'Angular' iniciado por Manoj Shrestha, Novembro 27, 2024.

  1. What are the differences between [ngSwitch] and a bunch of *ngIfs. Any performance factors we should be concerned about?

    *ngIf

    <div *ngIf="day === 'MONDAY'">
    Keep calm and pretend it's not Monday.
    </div>
    ...
    <div *ngIf="day === 'FRIDAY'">
    Happy Friday!
    </div>


    [ngSwitch]

    <ng-container [ngSwitch]="day">

    <div *ngSwitchCase="'MONDAY'">
    Keep calm and pretend it's not Monday.
    </div>
    ...
    <div *ngSwitchCase="'FRIDAY'">
    Happy Friday!
    </div>

    </ng-container>

    Continue reading...

Compartilhe esta Página