Angular: change style depending on *ngIf condition

Discussão em 'Angular' iniciado por user16241255, Fevereiro 16, 2025.

  1. user16241255

    user16241255 Guest

    I'm aware that I can do something like this:

    <ng-container *ngIf="user.age<18;else over">
    <div class="some-section" style="background-color: red;">
    [...]
    </div>
    </ng-container>
    <ng-template #over>
    <div class="some-section" style="background-color: blue;">
    [...]
    </div>
    </ng-template>


    Although this works, it is duplicate code. Is there a way to change only the style so that there's no duplicates (scss, other angular tools, ...)?

    Continue reading...

Compartilhe esta Página