Angular 2 Doing an else with ngClass

前端 未结 1 782
一整个雨季
一整个雨季 2021-02-05 01:24

I have the following template :

While this is working, I find it a bit ugl

相关标签:
1条回答
  • 2021-02-05 01:33

    Indeed

    <p class="{{condition ? 'checked' : 'unchecked'}}">
    

    or

    <p [ngClass]="condition ? 'checked' : 'unchecked'">
    

    or

    <p [ngClass]="[condition ? 'checked' : 'unchecked']">
    

    Angular 9 Update

    But you should know that there's a difference in how different types of class bindings behave, especially when there are multiple types of class bindings on the same element.

    And the new compiler, Ivy, brings more clarity and predictability to it. Read More about it here

    0 讨论(0)
提交回复
热议问题