1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular 2 ngSwitchCase, OR operator not working

Discussão em 'Angular' iniciado por PaladiN, Setembro 27, 2024.

  1. PaladiN

    PaladiN Guest

    I have multiple switch statement but for some case i need the common case. So, i am trying the

    OR operator => ||

    Example:

    <ng-container [ngSwitch]="options">
    <ng-container *ngSwitchCase="'a'">Code A</ng-container>
    <ng-container *ngSwitchCase="'b'">Code B</ng-container>
    <ng-container *ngSwitchCase="'c'">Code C</ng-container>
    <ng-container *ngSwitchCase="'d' || 'e' || 'f'">Common Code</ng-container>
    <ng-container *ngSwitchDefault>Code Default</ng-container>
    </ng-container>


    Output:

    if case = 'd' returns Common Code
    else if case = 'e' and 'f' returns the Code Default


    Here the second last case consists of multiple cases, and now by default the case 'd' is only working and not working for case 'e' and 'f'.

    I can't see any multiple case inside the ngSwitchCase docs:


    Doesn't Angular 2 supports the || operator in the ngSwitchCase?

    Continue reading...

Compartilhe esta Página